diff options
Diffstat (limited to 'src/plugins/old')
-rw-r--r-- | src/plugins/old/applefile_extractor.c | 267 | ||||
-rw-r--r-- | src/plugins/old/asf_extractor.c | 440 | ||||
-rw-r--r-- | src/plugins/old/convert_numeric.c | 423 | ||||
-rw-r--r-- | src/plugins/old/convert_numeric.h | 42 | ||||
-rw-r--r-- | src/plugins/old/ebml_extractor.c | 509 | ||||
-rw-r--r-- | src/plugins/old/elf_extractor.c | 585 | ||||
-rw-r--r-- | src/plugins/old/flv_extractor.c | 878 | ||||
-rw-r--r-- | src/plugins/old/mkv_extractor.c | 144 | ||||
-rw-r--r-- | src/plugins/old/mp3_extractor.c | 110 | ||||
-rw-r--r-- | src/plugins/old/pack.c | 538 | ||||
-rw-r--r-- | src/plugins/old/pack.h | 14 | ||||
-rw-r--r-- | src/plugins/old/qt_extractor.c | 272 | ||||
-rw-r--r-- | src/plugins/old/real_extractor.c | 421 |
13 files changed, 2542 insertions, 2101 deletions
diff --git a/src/plugins/old/applefile_extractor.c b/src/plugins/old/applefile_extractor.c index cc82dc8..dcaf7d0 100644 --- a/src/plugins/old/applefile_extractor.c +++ b/src/plugins/old/applefile_extractor.c | |||
@@ -42,10 +42,10 @@ typedef struct | |||
42 | #define APPLEFILE_HEADER_SIZE 26 | 42 | #define APPLEFILE_HEADER_SIZE 26 |
43 | #define APPLEFILE_HEADER_SPEC "4bW16bH" | 43 | #define APPLEFILE_HEADER_SPEC "4bW16bH" |
44 | #define APPLEFILE_HEADER_FIELDS(p) \ | 44 | #define APPLEFILE_HEADER_FIELDS(p) \ |
45 | &(p)->magic, \ | 45 | & (p)->magic, \ |
46 | &(p)->version, \ | 46 | &(p)->version, \ |
47 | &(p)->homeFileSystem, \ | 47 | &(p)->homeFileSystem, \ |
48 | &(p)->entries | 48 | &(p)->entries |
49 | 49 | ||
50 | typedef struct | 50 | typedef struct |
51 | { | 51 | { |
@@ -57,9 +57,9 @@ typedef struct | |||
57 | #define APPLEFILE_ENTRY_DESCRIPTOR_SIZE 12 | 57 | #define APPLEFILE_ENTRY_DESCRIPTOR_SIZE 12 |
58 | #define APPLEFILE_ENTRY_DESCRIPTOR_SPEC "WWW" | 58 | #define APPLEFILE_ENTRY_DESCRIPTOR_SPEC "WWW" |
59 | #define APPLEFILE_ENTRY_DESCRIPTOR_FIELDS(p) \ | 59 | #define APPLEFILE_ENTRY_DESCRIPTOR_FIELDS(p) \ |
60 | &(p)->id, \ | 60 | & (p)->id, \ |
61 | &(p)->offset, \ | 61 | &(p)->offset, \ |
62 | &(p)->length | 62 | &(p)->length |
63 | 63 | ||
64 | #define AED_ID_DATA_FORK 1 | 64 | #define AED_ID_DATA_FORK 1 |
65 | #define AED_ID_RESOURCE_FORK 2 | 65 | #define AED_ID_RESOURCE_FORK 2 |
@@ -76,43 +76,47 @@ typedef struct | |||
76 | #define AED_ID_AFP_FILE_INFO 14 | 76 | #define AED_ID_AFP_FILE_INFO 14 |
77 | #define AED_ID_DIRECTORY_ID 15 | 77 | #define AED_ID_DIRECTORY_ID 15 |
78 | 78 | ||
79 | static int readApplefileHeader(const unsigned char *data, | 79 | static int |
80 | size_t *offset, | 80 | readApplefileHeader (const unsigned char *data, |
81 | size_t size, | 81 | size_t *offset, |
82 | ApplefileHeader *hdr) | 82 | size_t size, |
83 | ApplefileHeader *hdr) | ||
83 | { | 84 | { |
84 | if ((*offset + APPLEFILE_HEADER_SIZE) > size) | 85 | if ((*offset + APPLEFILE_HEADER_SIZE) > size) |
85 | return -1; | 86 | return -1; |
86 | 87 | ||
87 | EXTRACTOR_common_cat_unpack(data + *offset, | 88 | EXTRACTOR_common_cat_unpack (data + *offset, |
88 | APPLEFILE_HEADER_SPEC, | 89 | APPLEFILE_HEADER_SPEC, |
89 | APPLEFILE_HEADER_FIELDS(hdr)); | 90 | APPLEFILE_HEADER_FIELDS (hdr)); |
90 | *offset += APPLEFILE_HEADER_SIZE; | 91 | *offset += APPLEFILE_HEADER_SIZE; |
91 | return 0; | 92 | return 0; |
92 | } | 93 | } |
93 | 94 | ||
94 | static int readEntryDescriptor(const unsigned char *data, | 95 | |
95 | size_t *offset, | 96 | static int |
96 | size_t size, | 97 | readEntryDescriptor (const unsigned char *data, |
97 | ApplefileEntryDescriptor *dsc) | 98 | size_t *offset, |
99 | size_t size, | ||
100 | ApplefileEntryDescriptor *dsc) | ||
98 | { | 101 | { |
99 | if ((*offset + APPLEFILE_ENTRY_DESCRIPTOR_SIZE) > size) | 102 | if ((*offset + APPLEFILE_ENTRY_DESCRIPTOR_SIZE) > size) |
100 | return -1; | 103 | return -1; |
101 | 104 | ||
102 | EXTRACTOR_common_cat_unpack(data + *offset, | 105 | EXTRACTOR_common_cat_unpack (data + *offset, |
103 | APPLEFILE_ENTRY_DESCRIPTOR_SPEC, | 106 | APPLEFILE_ENTRY_DESCRIPTOR_SPEC, |
104 | APPLEFILE_ENTRY_DESCRIPTOR_FIELDS(dsc)); | 107 | APPLEFILE_ENTRY_DESCRIPTOR_FIELDS (dsc)); |
105 | *offset += APPLEFILE_ENTRY_DESCRIPTOR_SIZE; | 108 | *offset += APPLEFILE_ENTRY_DESCRIPTOR_SIZE; |
106 | return 0; | 109 | return 0; |
107 | } | 110 | } |
108 | 111 | ||
112 | |||
109 | /* mimetype = application/applefile */ | 113 | /* mimetype = application/applefile */ |
110 | int | 114 | int |
111 | EXTRACTOR_applefile_extract (const char *sdata, | 115 | EXTRACTOR_applefile_extract (const char *sdata, |
112 | size_t size, | 116 | size_t size, |
113 | EXTRACTOR_MetaDataProcessor proc, | 117 | EXTRACTOR_MetaDataProcessor proc, |
114 | void *proc_cls, | 118 | void *proc_cls, |
115 | const char *options) | 119 | const char *options) |
116 | { | 120 | { |
117 | const unsigned char *data = (const unsigned char*) sdata; | 121 | const unsigned char *data = (const unsigned char*) sdata; |
118 | size_t offset; | 122 | size_t offset; |
@@ -121,129 +125,134 @@ EXTRACTOR_applefile_extract (const char *sdata, | |||
121 | int i; | 125 | int i; |
122 | 126 | ||
123 | offset = 0; | 127 | offset = 0; |
124 | if (readApplefileHeader(data, &offset, size, &header) == -1) | 128 | if (readApplefileHeader (data, &offset, size, &header) == -1) |
125 | return 0; | 129 | return 0; |
126 | if ( (memcmp(header.magic, APPLESINGLE_SIGNATURE, 4) != 0) && | 130 | if ( (memcmp (header.magic, APPLESINGLE_SIGNATURE, 4) != 0) && |
127 | (memcmp(header.magic, APPLEDOUBLE_SIGNATURE, 4) != 0) ) | 131 | (memcmp (header.magic, APPLEDOUBLE_SIGNATURE, 4) != 0) ) |
128 | return 0; | 132 | return 0; |
129 | if (0 != proc (proc_cls, | 133 | if (0 != proc (proc_cls, |
130 | "applefile", | 134 | "applefile", |
131 | EXTRACTOR_METATYPE_MIMETYPE, | 135 | EXTRACTOR_METATYPE_MIMETYPE, |
132 | EXTRACTOR_METAFORMAT_UTF8, | 136 | EXTRACTOR_METAFORMAT_UTF8, |
133 | "text/plain", | 137 | "text/plain", |
134 | "application/applefile", | 138 | "application/applefile", |
135 | strlen ("application/applefile")+1)) | 139 | strlen ("application/applefile") + 1)) |
136 | return 1; | 140 | return 1; |
137 | #if DEBUG | 141 | #if DEBUG |
138 | fprintf(stderr, | 142 | fprintf (stderr, |
139 | "applefile header: %08x %d\n", header.version, header.entries); | 143 | "applefile header: %08x %d\n", header.version, header.entries); |
140 | #endif | 144 | #endif |
141 | if ( (header.version != 0x00010000) && | 145 | if ( (header.version != 0x00010000) && |
142 | (header.version != 0x00020000) ) | 146 | (header.version != 0x00020000) ) |
143 | return 0; | 147 | return 0; |
144 | 148 | ||
145 | for (i = 0; i < header.entries; i++) { | 149 | for (i = 0; i < header.entries; i++) |
146 | if (readEntryDescriptor(data, &offset, size, &dsc) == -1) | 150 | { |
151 | if (readEntryDescriptor (data, &offset, size, &dsc) == -1) | ||
147 | break; | 152 | break; |
148 | 153 | ||
149 | #if DEBUG | 154 | #if DEBUG |
150 | fprintf(stderr, | 155 | fprintf (stderr, |
151 | "applefile entry: %u %u %u\n", dsc.id, dsc.offset, dsc.length); | 156 | "applefile entry: %u %u %u\n", dsc.id, dsc.offset, dsc.length); |
152 | #endif | 157 | #endif |
153 | switch (dsc.id) | 158 | switch (dsc.id) |
159 | { | ||
160 | case AED_ID_DATA_FORK: | ||
154 | { | 161 | { |
155 | case AED_ID_DATA_FORK: | 162 | /* same as in filenameextractor.c */ |
156 | { | 163 | char s[14]; |
157 | /* same as in filenameextractor.c */ | ||
158 | char s[14]; | ||
159 | 164 | ||
160 | if (dsc.length >= 1000000000) | 165 | if (dsc.length >= 1000000000) |
161 | snprintf (s, 13, "%.2f %s", dsc.length / 1000000000.0, | 166 | snprintf (s, 13, "%.2f %s", dsc.length / 1000000000.0, |
162 | _("GB")); | 167 | _ ("GB")); |
163 | else if (dsc.length >= 1000000) | 168 | else if (dsc.length >= 1000000) |
164 | snprintf (s, 13, "%.2f %s", dsc.length / 1000000.0, _("MB")); | 169 | snprintf (s, 13, "%.2f %s", dsc.length / 1000000.0, _ ("MB")); |
165 | else if (dsc.length >= 1000) | 170 | else if (dsc.length >= 1000) |
166 | snprintf (s, 13, "%.2f %s", dsc.length / 1000.0, _("KB")); | 171 | snprintf (s, 13, "%.2f %s", dsc.length / 1000.0, _ ("KB")); |
167 | else | 172 | else |
168 | snprintf (s, 13, "%.2f %s", (double) dsc.length, _("Bytes")); | 173 | snprintf (s, 13, "%.2f %s", (double) dsc.length, _ ("Bytes")); |
169 | 174 | ||
170 | if (0 != proc (proc_cls, | 175 | if (0 != proc (proc_cls, |
171 | "applefile", | 176 | "applefile", |
172 | EXTRACTOR_METATYPE_EMBEDDED_FILE_SIZE, | 177 | EXTRACTOR_METATYPE_EMBEDDED_FILE_SIZE, |
173 | EXTRACTOR_METAFORMAT_UTF8, | 178 | EXTRACTOR_METAFORMAT_UTF8, |
174 | "text/plain", | 179 | "text/plain", |
175 | s, | 180 | s, |
176 | strlen (s) + 1)) | 181 | strlen (s) + 1)) |
177 | return 1; | 182 | return 1; |
178 | } | 183 | } |
179 | break; | 184 | break; |
180 | case AED_ID_REAL_NAME: | 185 | case AED_ID_REAL_NAME: |
181 | { | 186 | { |
182 | char s[2048]; | 187 | char s[2048]; |
183 | if ( (dsc.length < sizeof(s)) && | 188 | if ( (dsc.length < sizeof(s)) && |
184 | ((dsc.offset + dsc.length) < size) ) { | 189 | ((dsc.offset + dsc.length) < size) ) |
185 | memcpy(s, data + dsc.offset, dsc.length); | 190 | { |
186 | s[dsc.length] = '\0'; | 191 | memcpy (s, data + dsc.offset, dsc.length); |
187 | if (0 != proc (proc_cls, | 192 | s[dsc.length] = '\0'; |
188 | "applefile", | 193 | if (0 != proc (proc_cls, |
189 | EXTRACTOR_METATYPE_FILENAME, | 194 | "applefile", |
190 | EXTRACTOR_METAFORMAT_UTF8, | 195 | EXTRACTOR_METATYPE_FILENAME, |
191 | "text/plain", | 196 | EXTRACTOR_METAFORMAT_UTF8, |
192 | s, | 197 | "text/plain", |
193 | dsc.length + 1)) | 198 | s, |
194 | return 1; | 199 | dsc.length + 1)) |
195 | } | 200 | return 1; |
196 | } | 201 | } |
197 | break; | 202 | } |
198 | case AED_ID_COMMENT: | 203 | break; |
199 | if ( (dsc.length < 65536) && ((dsc.offset + dsc.length) < size) ) { | 204 | case AED_ID_COMMENT: |
200 | char *s = malloc(dsc.length + 1); | 205 | if ( (dsc.length < 65536) && ((dsc.offset + dsc.length) < size) ) |
201 | if (s != NULL) { | 206 | { |
202 | memcpy(s, data + dsc.offset, dsc.length); | 207 | char *s = malloc (dsc.length + 1); |
203 | s[dsc.length] = '\0'; | 208 | if (s != NULL) |
204 | if (0 != proc (proc_cls, | 209 | { |
205 | "applefile", | 210 | memcpy (s, data + dsc.offset, dsc.length); |
206 | EXTRACTOR_METATYPE_COMMENT, | 211 | s[dsc.length] = '\0'; |
207 | EXTRACTOR_METAFORMAT_UTF8, | 212 | if (0 != proc (proc_cls, |
208 | "text/plain", | 213 | "applefile", |
209 | s, | 214 | EXTRACTOR_METATYPE_COMMENT, |
210 | dsc.length + 1)) | 215 | EXTRACTOR_METAFORMAT_UTF8, |
211 | { | 216 | "text/plain", |
212 | free (s); | 217 | s, |
213 | return 1; | 218 | dsc.length + 1)) |
214 | } | 219 | { |
215 | free (s); | 220 | free (s); |
216 | } | 221 | return 1; |
217 | } | 222 | } |
218 | break; | 223 | free (s); |
219 | case AED_ID_FINDER_INFO: | ||
220 | if (dsc.length >= 16 && (dsc.offset + dsc.length) < size) { | ||
221 | char s[5]; | ||
222 | memcpy(s, data + dsc.offset, 4); | ||
223 | s[4] = '\0'; | ||
224 | if (0 != proc (proc_cls, | ||
225 | "applefile", | ||
226 | EXTRACTOR_METATYPE_FINDER_FILE_TYPE, | ||
227 | EXTRACTOR_METAFORMAT_C_STRING, | ||
228 | "text/plain", | ||
229 | s, | ||
230 | strlen(s) + 1)) | ||
231 | return 1; | ||
232 | |||
233 | memcpy(s, data + dsc.offset + 4, 4); | ||
234 | s[4] = '\0'; | ||
235 | if (0 != proc (proc_cls, | ||
236 | "applefile", | ||
237 | EXTRACTOR_METATYPE_FINDER_FILE_CREATOR, | ||
238 | EXTRACTOR_METAFORMAT_C_STRING, | ||
239 | "text/plain", | ||
240 | s, | ||
241 | strlen(s) + 1)) | ||
242 | return 1; | ||
243 | } | 224 | } |
244 | break; | 225 | } |
245 | default: | 226 | break; |
246 | break; | 227 | case AED_ID_FINDER_INFO: |
228 | if ((dsc.length >= 16) && ( (dsc.offset + dsc.length) < size) ) | ||
229 | { | ||
230 | char s[5]; | ||
231 | memcpy (s, data + dsc.offset, 4); | ||
232 | s[4] = '\0'; | ||
233 | if (0 != proc (proc_cls, | ||
234 | "applefile", | ||
235 | EXTRACTOR_METATYPE_FINDER_FILE_TYPE, | ||
236 | EXTRACTOR_METAFORMAT_C_STRING, | ||
237 | "text/plain", | ||
238 | s, | ||
239 | strlen (s) + 1)) | ||
240 | return 1; | ||
241 | |||
242 | memcpy (s, data + dsc.offset + 4, 4); | ||
243 | s[4] = '\0'; | ||
244 | if (0 != proc (proc_cls, | ||
245 | "applefile", | ||
246 | EXTRACTOR_METATYPE_FINDER_FILE_CREATOR, | ||
247 | EXTRACTOR_METAFORMAT_C_STRING, | ||
248 | "text/plain", | ||
249 | s, | ||
250 | strlen (s) + 1)) | ||
251 | return 1; | ||
252 | } | ||
253 | break; | ||
254 | default: | ||
255 | break; | ||
247 | } | 256 | } |
248 | } | 257 | } |
249 | return 0; | 258 | return 0; |
diff --git a/src/plugins/old/asf_extractor.c b/src/plugins/old/asf_extractor.c index 0581ded..6be0a16 100644 --- a/src/plugins/old/asf_extractor.c +++ b/src/plugins/old/asf_extractor.c | |||
@@ -110,199 +110,288 @@ static const struct | |||
110 | { | 110 | { |
111 | const char *name; | 111 | const char *name; |
112 | const LE_GUID guid; | 112 | const LE_GUID guid; |
113 | } guids[] = | 113 | } guids[] = { |
114 | { | ||
115 | { | 114 | { |
116 | "error", | 115 | "error", |
117 | { | 116 | { |
118 | 0x0,}}, | 117 | 0x0, |
119 | /* base ASF objects */ | 118 | } |
119 | }, | ||
120 | /* base ASF objects */ | ||
120 | { | 121 | { |
121 | "header", | 122 | "header", |
122 | { | 123 | { |
123 | 0x75b22630, 0x668e, 0x11cf, | 124 | 0x75b22630, 0x668e, 0x11cf, |
124 | { | 125 | { |
125 | 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}}}, | 126 | 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c |
127 | } | ||
128 | } | ||
129 | }, | ||
126 | { | 130 | { |
127 | "data", | 131 | "data", |
128 | { | 132 | { |
129 | 0x75b22636, 0x668e, 0x11cf, | 133 | 0x75b22636, 0x668e, 0x11cf, |
130 | { | 134 | { |
131 | 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}}}, | 135 | 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c |
136 | } | ||
137 | } | ||
138 | }, | ||
132 | { | 139 | { |
133 | "simple index", | 140 | "simple index", |
134 | { | 141 | { |
135 | 0x33000890, 0xe5b1, 0x11cf, | 142 | 0x33000890, 0xe5b1, 0x11cf, |
136 | { | 143 | { |
137 | 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb}}}, | 144 | 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb |
138 | /* header ASF objects */ | 145 | } |
146 | } | ||
147 | }, | ||
148 | /* header ASF objects */ | ||
139 | { | 149 | { |
140 | "file properties", | 150 | "file properties", |
141 | { | 151 | { |
142 | 0x8cabdca1, 0xa947, 0x11cf, | 152 | 0x8cabdca1, 0xa947, 0x11cf, |
143 | { | 153 | { |
144 | 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, | 154 | 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 |
155 | } | ||
156 | } | ||
157 | }, | ||
145 | { | 158 | { |
146 | "stream header", | 159 | "stream header", |
147 | { | 160 | { |
148 | 0xb7dc0791, 0xa9b7, 0x11cf, | 161 | 0xb7dc0791, 0xa9b7, 0x11cf, |
149 | { | 162 | { |
150 | 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, | 163 | 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 |
164 | } | ||
165 | } | ||
166 | }, | ||
151 | { | 167 | { |
152 | "stream bitrate properties", /* (http://get.to/sdp) */ | 168 | "stream bitrate properties", /* (http://get.to/sdp) */ |
153 | { | 169 | { |
154 | 0x7bf875ce, 0x468d, 0x11d1, | 170 | 0x7bf875ce, 0x468d, 0x11d1, |
155 | { | 171 | { |
156 | 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2}}}, | 172 | 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2 |
173 | } | ||
174 | } | ||
175 | }, | ||
157 | { | 176 | { |
158 | "content description", | 177 | "content description", |
159 | { | 178 | { |
160 | 0x75b22633, 0x668e, 0x11cf, | 179 | 0x75b22633, 0x668e, 0x11cf, |
161 | { | 180 | { |
162 | 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}}}, | 181 | 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c |
182 | } | ||
183 | } | ||
184 | }, | ||
163 | { | 185 | { |
164 | "extended content encryption", | 186 | "extended content encryption", |
165 | { | 187 | { |
166 | 0x298ae614, 0x2622, 0x4c17, | 188 | 0x298ae614, 0x2622, 0x4c17, |
167 | { | 189 | { |
168 | 0xb9, 0x35, 0xda, 0xe0, 0x7e, 0xe9, 0x28, 0x9c}}}, | 190 | 0xb9, 0x35, 0xda, 0xe0, 0x7e, 0xe9, 0x28, 0x9c |
191 | } | ||
192 | } | ||
193 | }, | ||
169 | { | 194 | { |
170 | "script command", | 195 | "script command", |
171 | { | 196 | { |
172 | 0x1efb1a30, 0x0b62, 0x11d0, | 197 | 0x1efb1a30, 0x0b62, 0x11d0, |
173 | { | 198 | { |
174 | 0xa3, 0x9b, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, | 199 | 0xa3, 0x9b, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 |
200 | } | ||
201 | } | ||
202 | }, | ||
175 | { | 203 | { |
176 | "marker", | 204 | "marker", |
177 | { | 205 | { |
178 | 0xf487cd01, 0xa951, 0x11cf, | 206 | 0xf487cd01, 0xa951, 0x11cf, |
179 | { | 207 | { |
180 | 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, | 208 | 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 |
209 | } | ||
210 | } | ||
211 | }, | ||
181 | { | 212 | { |
182 | "header extension", | 213 | "header extension", |
183 | { | 214 | { |
184 | 0x5fbf03b5, 0xa92e, 0x11cf, | 215 | 0x5fbf03b5, 0xa92e, 0x11cf, |
185 | { | 216 | { |
186 | 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, | 217 | 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 |
218 | } | ||
219 | } | ||
220 | }, | ||
187 | { | 221 | { |
188 | "bitrate mutual exclusion", | 222 | "bitrate mutual exclusion", |
189 | { | 223 | { |
190 | 0xd6e229dc, 0x35da, 0x11d1, | 224 | 0xd6e229dc, 0x35da, 0x11d1, |
191 | { | 225 | { |
192 | 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe}}}, | 226 | 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe |
227 | } | ||
228 | } | ||
229 | }, | ||
193 | { | 230 | { |
194 | "codec list", | 231 | "codec list", |
195 | { | 232 | { |
196 | 0x86d15240, 0x311d, 0x11d0, | 233 | 0x86d15240, 0x311d, 0x11d0, |
197 | { | 234 | { |
198 | 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, | 235 | 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 |
236 | } | ||
237 | } | ||
238 | }, | ||
199 | { | 239 | { |
200 | "extended content description", | 240 | "extended content description", |
201 | { | 241 | { |
202 | 0xd2d0a440, 0xe307, 0x11d2, | 242 | 0xd2d0a440, 0xe307, 0x11d2, |
203 | { | 243 | { |
204 | 0x97, 0xf0, 0x00, 0xa0, 0xc9, 0x5e, 0xa8, 0x50}}}, | 244 | 0x97, 0xf0, 0x00, 0xa0, 0xc9, 0x5e, 0xa8, 0x50 |
245 | } | ||
246 | } | ||
247 | }, | ||
205 | { | 248 | { |
206 | "error correction", | 249 | "error correction", |
207 | { | 250 | { |
208 | 0x75b22635, 0x668e, 0x11cf, | 251 | 0x75b22635, 0x668e, 0x11cf, |
209 | { | 252 | { |
210 | 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}}}, | 253 | 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c |
254 | } | ||
255 | } | ||
256 | }, | ||
211 | { | 257 | { |
212 | "padding", | 258 | "padding", |
213 | { | 259 | { |
214 | 0x1806d474, 0xcadf, 0x4509, | 260 | 0x1806d474, 0xcadf, 0x4509, |
215 | { | 261 | { |
216 | 0xa4, 0xba, 0x9a, 0xab, 0xcb, 0x96, 0xaa, 0xe8}}}, | 262 | 0xa4, 0xba, 0x9a, 0xab, 0xcb, 0x96, 0xaa, 0xe8 |
217 | /* stream properties object stream type */ | 263 | } |
264 | } | ||
265 | }, | ||
266 | /* stream properties object stream type */ | ||
218 | { | 267 | { |
219 | "audio media", | 268 | "audio media", |
220 | { | 269 | { |
221 | 0xf8699e40, 0x5b4d, 0x11cf, | 270 | 0xf8699e40, 0x5b4d, 0x11cf, |
222 | { | 271 | { |
223 | 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b}}}, | 272 | 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b |
273 | } | ||
274 | } | ||
275 | }, | ||
224 | { | 276 | { |
225 | "video media", | 277 | "video media", |
226 | { | 278 | { |
227 | 0xbc19efc0, 0x5b4d, 0x11cf, | 279 | 0xbc19efc0, 0x5b4d, 0x11cf, |
228 | { | 280 | { |
229 | 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b}}}, | 281 | 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b |
282 | } | ||
283 | } | ||
284 | }, | ||
230 | { | 285 | { |
231 | "command media", | 286 | "command media", |
232 | { | 287 | { |
233 | 0x59dacfc0, 0x59e6, 0x11d0, | 288 | 0x59dacfc0, 0x59e6, 0x11d0, |
234 | { | 289 | { |
235 | 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, | 290 | 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 |
236 | /* stream properties object error correction */ | 291 | } |
292 | } | ||
293 | }, | ||
294 | /* stream properties object error correction */ | ||
237 | { | 295 | { |
238 | "no error correction", | 296 | "no error correction", |
239 | { | 297 | { |
240 | 0x20fb5700, 0x5b55, 0x11cf, | 298 | 0x20fb5700, 0x5b55, 0x11cf, |
241 | { | 299 | { |
242 | 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b}}}, | 300 | 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b |
301 | } | ||
302 | } | ||
303 | }, | ||
243 | { | 304 | { |
244 | "audio spread", | 305 | "audio spread", |
245 | { | 306 | { |
246 | 0xbfc3cd50, 0x618f, 0x11cf, | 307 | 0xbfc3cd50, 0x618f, 0x11cf, |
247 | { | 308 | { |
248 | 0x8b, 0xb2, 0x00, 0xaa, 0x00, 0xb4, 0xe2, 0x20}}}, | 309 | 0x8b, 0xb2, 0x00, 0xaa, 0x00, 0xb4, 0xe2, 0x20 |
249 | /* mutual exclusion object exlusion type */ | 310 | } |
311 | } | ||
312 | }, | ||
313 | /* mutual exclusion object exlusion type */ | ||
250 | { | 314 | { |
251 | "mutex bitrate", | 315 | "mutex bitrate", |
252 | { | 316 | { |
253 | 0xd6e22a01, 0x35da, 0x11d1, | 317 | 0xd6e22a01, 0x35da, 0x11d1, |
254 | { | 318 | { |
255 | 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe}}}, | 319 | 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe |
320 | } | ||
321 | } | ||
322 | }, | ||
256 | { | 323 | { |
257 | "mutex unknown", | 324 | "mutex unknown", |
258 | { | 325 | { |
259 | 0xd6e22a02, 0x35da, 0x11d1, | 326 | 0xd6e22a02, 0x35da, 0x11d1, |
260 | { | 327 | { |
261 | 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe}}}, | 328 | 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe |
262 | /* header extension */ | 329 | } |
330 | } | ||
331 | }, | ||
332 | /* header extension */ | ||
263 | { | 333 | { |
264 | "reserved_1", | 334 | "reserved_1", |
265 | { | 335 | { |
266 | 0xabd3d211, 0xa9ba, 0x11cf, | 336 | 0xabd3d211, 0xa9ba, 0x11cf, |
267 | { | 337 | { |
268 | 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, | 338 | 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 |
269 | /* script command */ | 339 | } |
340 | } | ||
341 | }, | ||
342 | /* script command */ | ||
270 | { | 343 | { |
271 | "reserved script command", | 344 | "reserved script command", |
272 | { | 345 | { |
273 | 0x4B1ACBE3, 0x100B, 0x11D0, | 346 | 0x4B1ACBE3, 0x100B, 0x11D0, |
274 | { | 347 | { |
275 | 0xA3, 0x9B, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}}}, | 348 | 0xA3, 0x9B, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 |
276 | /* marker object */ | 349 | } |
350 | } | ||
351 | }, | ||
352 | /* marker object */ | ||
277 | { | 353 | { |
278 | "reserved marker", | 354 | "reserved marker", |
279 | { | 355 | { |
280 | 0x4CFEDB20, 0x75F6, 0x11CF, | 356 | 0x4CFEDB20, 0x75F6, 0x11CF, |
281 | { | 357 | { |
282 | 0x9C, 0x0F, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB}}}, | 358 | 0x9C, 0x0F, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB |
283 | /* various */ | 359 | } |
284 | /* Already defined (reserved_1) | 360 | } |
285 | { "head2", | 361 | }, |
286 | { 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }} }, | 362 | /* various */ |
287 | */ | 363 | /* Already defined (reserved_1) |
364 | { "head2", | ||
365 | { 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }} }, | ||
366 | */ | ||
288 | { | 367 | { |
289 | "audio conceal none", | 368 | "audio conceal none", |
290 | { | 369 | { |
291 | 0x49f1a440, 0x4ece, 0x11d0, | 370 | 0x49f1a440, 0x4ece, 0x11d0, |
292 | { | 371 | { |
293 | 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, | 372 | 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 |
373 | } | ||
374 | } | ||
375 | }, | ||
294 | { | 376 | { |
295 | "codec comment1 header", | 377 | "codec comment1 header", |
296 | { | 378 | { |
297 | 0x86d15241, 0x311d, 0x11d0, | 379 | 0x86d15241, 0x311d, 0x11d0, |
298 | { | 380 | { |
299 | 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, | 381 | 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 |
382 | } | ||
383 | } | ||
384 | }, | ||
300 | { | 385 | { |
301 | "asf 2.0 header", | 386 | "asf 2.0 header", |
302 | { | 387 | { |
303 | 0xd6e229d1, 0x35da, 0x11d1, | 388 | 0xd6e229d1, 0x35da, 0x11d1, |
304 | { | 389 | { |
305 | 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe}}},}; | 390 | 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe |
391 | } | ||
392 | } | ||
393 | }, | ||
394 | }; | ||
306 | 395 | ||
307 | 396 | ||
308 | struct demux_asf_s | 397 | struct demux_asf_s |
@@ -326,7 +415,7 @@ struct demux_asf_s | |||
326 | }; | 415 | }; |
327 | 416 | ||
328 | static int | 417 | static int |
329 | readBuf (struct demux_asf_s * this, void *buf, int len) | 418 | readBuf (struct demux_asf_s *this, void *buf, int len) |
330 | { | 419 | { |
331 | int min; | 420 | int min; |
332 | 421 | ||
@@ -338,8 +427,9 @@ readBuf (struct demux_asf_s * this, void *buf, int len) | |||
338 | return min; | 427 | return min; |
339 | } | 428 | } |
340 | 429 | ||
430 | |||
341 | static uint8_t | 431 | static uint8_t |
342 | get_byte (struct demux_asf_s * this) | 432 | get_byte (struct demux_asf_s *this) |
343 | { | 433 | { |
344 | uint8_t buf; | 434 | uint8_t buf; |
345 | int i; | 435 | int i; |
@@ -350,8 +440,9 @@ get_byte (struct demux_asf_s * this) | |||
350 | return buf; | 440 | return buf; |
351 | } | 441 | } |
352 | 442 | ||
443 | |||
353 | static uint16_t | 444 | static uint16_t |
354 | get_le16 (struct demux_asf_s * this) | 445 | get_le16 (struct demux_asf_s *this) |
355 | { | 446 | { |
356 | uint8_t buf[2]; | 447 | uint8_t buf[2]; |
357 | int i; | 448 | int i; |
@@ -362,8 +453,9 @@ get_le16 (struct demux_asf_s * this) | |||
362 | return buf[0] | (buf[1] << 8); | 453 | return buf[0] | (buf[1] << 8); |
363 | } | 454 | } |
364 | 455 | ||
456 | |||
365 | static uint32_t | 457 | static uint32_t |
366 | get_le32 (struct demux_asf_s * this) | 458 | get_le32 (struct demux_asf_s *this) |
367 | { | 459 | { |
368 | uint8_t buf[4]; | 460 | uint8_t buf[4]; |
369 | int i; | 461 | int i; |
@@ -374,8 +466,9 @@ get_le32 (struct demux_asf_s * this) | |||
374 | return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); | 466 | return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); |
375 | } | 467 | } |
376 | 468 | ||
469 | |||
377 | static uint64_t | 470 | static uint64_t |
378 | get_le64 (struct demux_asf_s * this) | 471 | get_le64 (struct demux_asf_s *this) |
379 | { | 472 | { |
380 | uint8_t buf[8]; | 473 | uint8_t buf[8]; |
381 | int i; | 474 | int i; |
@@ -384,16 +477,17 @@ get_le64 (struct demux_asf_s * this) | |||
384 | if (i != 8) | 477 | if (i != 8) |
385 | this->status = DEMUX_FINISHED; | 478 | this->status = DEMUX_FINISHED; |
386 | return (uint64_t) buf[0] | 479 | return (uint64_t) buf[0] |
387 | | ((uint64_t) buf[1] << 8) | 480 | | ((uint64_t) buf[1] << 8) |
388 | | ((uint64_t) buf[2] << 16) | 481 | | ((uint64_t) buf[2] << 16) |
389 | | ((uint64_t) buf[3] << 24) | 482 | | ((uint64_t) buf[3] << 24) |
390 | | ((uint64_t) buf[4] << 32) | 483 | | ((uint64_t) buf[4] << 32) |
391 | | ((uint64_t) buf[5] << 40) | 484 | | ((uint64_t) buf[5] << 40) |
392 | | ((uint64_t) buf[6] << 48) | ((uint64_t) buf[7] << 54); | 485 | | ((uint64_t) buf[6] << 48) | ((uint64_t) buf[7] << 54); |
393 | } | 486 | } |
394 | 487 | ||
488 | |||
395 | static int | 489 | static int |
396 | get_guid (struct demux_asf_s * this) | 490 | get_guid (struct demux_asf_s *this) |
397 | { | 491 | { |
398 | int i; | 492 | int i; |
399 | LE_GUID g; | 493 | LE_GUID g; |
@@ -406,7 +500,7 @@ get_guid (struct demux_asf_s * this) | |||
406 | if (this->status == DEMUX_FINISHED) | 500 | if (this->status == DEMUX_FINISHED) |
407 | return GUID_ERROR; | 501 | return GUID_ERROR; |
408 | for (i = 1; i < GUID_END; i++) | 502 | for (i = 1; i < GUID_END; i++) |
409 | if (!memcmp (&g, &guids[i].guid, sizeof (LE_GUID))) | 503 | if (! memcmp (&g, &guids[i].guid, sizeof (LE_GUID))) |
410 | return i; | 504 | return i; |
411 | 505 | ||
412 | return GUID_ERROR; | 506 | return GUID_ERROR; |
@@ -414,7 +508,7 @@ get_guid (struct demux_asf_s * this) | |||
414 | 508 | ||
415 | 509 | ||
416 | static int | 510 | static int |
417 | asf_read_header (struct demux_asf_s * this) | 511 | asf_read_header (struct demux_asf_s *this) |
418 | { | 512 | { |
419 | int guid; | 513 | int guid; |
420 | uint64_t gsize; | 514 | uint64_t gsize; |
@@ -426,62 +520,67 @@ asf_read_header (struct demux_asf_s * this) | |||
426 | get_le64 (this); /* object size */ | 520 | get_le64 (this); /* object size */ |
427 | get_le32 (this); /* number of header objects */ | 521 | get_le32 (this); /* number of header objects */ |
428 | get_byte (this); /* reserved 1 */ | 522 | get_byte (this); /* reserved 1 */ |
429 | get_byte (this); /* reserved 2 */ | 523 | get_byte (this); /* reserved 2 */ |
430 | while (this->status != DEMUX_FINISHED) | 524 | while (this->status != DEMUX_FINISHED) |
525 | { | ||
526 | guid = get_guid (this); /* object ID */ | ||
527 | gsize = get_le64 (this); /* object size */ | ||
528 | if (gsize < 24) | ||
529 | goto fail; | ||
530 | switch (guid) | ||
431 | { | 531 | { |
432 | guid = get_guid (this); /* object ID */ | 532 | case GUID_ASF_FILE_PROPERTIES: |
433 | gsize = get_le64 (this); /* object size */ | 533 | guid = get_guid (this); /* file ID */ |
434 | if (gsize < 24) | 534 | get_le64 (this); /* file size */ |
435 | goto fail; | 535 | get_le64 (this); /* creation date */ |
436 | switch (guid) | 536 | get_le64 (this); /* nb_packets */ |
437 | { | 537 | this->length = get_le64 (this); /* play duration in 100 ns units */ |
438 | case GUID_ASF_FILE_PROPERTIES: | 538 | get_le64 (this); /* send duration */ |
439 | guid = get_guid (this); /* file ID */ | 539 | get_le64 (this); /* preroll */ |
440 | get_le64 (this); /* file size */ | 540 | get_le32 (this); /* flags */ |
441 | get_le64 (this); /* creation date */ | 541 | get_le32 (this); /* min size */ |
442 | get_le64 (this); /* nb_packets */ | 542 | get_le32 (this); /* max size */ |
443 | this->length = get_le64 (this); /* play duration in 100 ns units */ | 543 | get_le32 (this); /* max bitrate */ |
444 | get_le64 (this); /* send duration */ | 544 | break; |
445 | get_le64 (this); /* preroll */ | 545 | case GUID_ASF_DATA: |
446 | get_le32 (this); /* flags */ | 546 | goto headers_ok; |
447 | get_le32 (this); /* min size */ | 547 | break; |
448 | get_le32 (this); /* max size */ | 548 | case GUID_ASF_CONTENT_DESCRIPTION: |
449 | get_le32 (this); /* max bitrate */ | 549 | len1 = get_le16 (this); |
450 | break; | 550 | len2 = get_le16 (this); |
451 | case GUID_ASF_DATA: | 551 | len3 = get_le16 (this); |
452 | goto headers_ok; | 552 | len4 = get_le16 (this); |
453 | break; | 553 | len5 = get_le16 (this); |
454 | case GUID_ASF_CONTENT_DESCRIPTION: | 554 | this->title = EXTRACTOR_common_convert_to_utf8 ( |
455 | len1 = get_le16 (this); | 555 | &this->input[this->inputPos], |
456 | len2 = get_le16 (this); | 556 | len1, |
457 | len3 = get_le16 (this); | 557 | "UTF-16"); |
458 | len4 = get_le16 (this); | 558 | this->inputPos += len1; |
459 | len5 = get_le16 (this); | 559 | this->author = EXTRACTOR_common_convert_to_utf8 ( |
460 | this->title = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], | 560 | &this->input[this->inputPos], |
461 | len1, | 561 | len2, |
462 | "UTF-16"); | 562 | "UTF-16"); |
463 | this->inputPos += len1; | 563 | this->inputPos += len2; |
464 | this->author = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], | 564 | this->copyright = EXTRACTOR_common_convert_to_utf8 ( |
465 | len2, | 565 | &this->input[this->inputPos], |
466 | "UTF-16"); | 566 | len3, |
467 | this->inputPos += len2; | 567 | "UTF-16"); |
468 | this->copyright = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], | 568 | this->inputPos += len3; |
469 | len3, | 569 | this->comment = EXTRACTOR_common_convert_to_utf8 ( |
470 | "UTF-16"); | 570 | &this->input[this->inputPos], |
471 | this->inputPos += len3; | 571 | len4, |
472 | this->comment = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], | 572 | "UTF-16"); |
473 | len4, | 573 | this->inputPos += len4; |
474 | "UTF-16"); | 574 | this->rating = EXTRACTOR_common_convert_to_utf8 ( |
475 | this->inputPos += len4; | 575 | &this->input[this->inputPos], |
476 | this->rating = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], | 576 | len5, |
477 | len5, | 577 | "UTF-16"); |
478 | "UTF-16"); | 578 | this->inputPos += len5; |
479 | this->inputPos += len5; | 579 | break; |
480 | break; | 580 | default: |
481 | default: | 581 | this->inputPos += gsize - 24; |
482 | this->inputPos += gsize - 24; | ||
483 | } | ||
484 | } | 582 | } |
583 | } | ||
485 | 584 | ||
486 | headers_ok: | 585 | headers_ok: |
487 | this->inputPos += sizeof (LE_GUID) + 10; | 586 | this->inputPos += sizeof (LE_GUID) + 10; |
@@ -502,12 +601,12 @@ fail: | |||
502 | video/x-ms-wax: wva: wma metafile; */ | 601 | video/x-ms-wax: wva: wma metafile; */ |
503 | 602 | ||
504 | /* mimetype = application/applefile */ | 603 | /* mimetype = application/applefile */ |
505 | int | 604 | int |
506 | EXTRACTOR_asf_extract (const char *data, | 605 | EXTRACTOR_asf_extract (const char *data, |
507 | size_t size, | 606 | size_t size, |
508 | EXTRACTOR_MetaDataProcessor proc, | 607 | EXTRACTOR_MetaDataProcessor proc, |
509 | void *proc_cls, | 608 | void *proc_cls, |
510 | const char *options) | 609 | const char *options) |
511 | { | 610 | { |
512 | struct demux_asf_s this; | 611 | struct demux_asf_s this; |
513 | size_t slen; | 612 | size_t slen; |
@@ -521,60 +620,60 @@ EXTRACTOR_asf_extract (const char *data, | |||
521 | ret = 0; | 620 | ret = 0; |
522 | if (1 == asf_read_header (&this)) | 621 | if (1 == asf_read_header (&this)) |
523 | { | 622 | { |
524 | snprintf (duration_str, | 623 | snprintf (duration_str, |
525 | sizeof (duration_str), | 624 | sizeof (duration_str), |
526 | "%llu ms", (unsigned long long) (this.length / 10000LL)); | 625 | "%llu ms", (unsigned long long) (this.length / 10000LL)); |
527 | if ( ( (this.title != NULL) && | 626 | if ( ( (this.title != NULL) && |
528 | (0 < (slen = strlen(this.title))) && | 627 | (0 < (slen = strlen (this.title))) && |
529 | (0 != proc (proc_cls, | 628 | (0 != proc (proc_cls, |
530 | "asf", | 629 | "asf", |
531 | EXTRACTOR_METATYPE_TITLE, | 630 | EXTRACTOR_METATYPE_TITLE, |
532 | EXTRACTOR_METAFORMAT_C_STRING, | 631 | EXTRACTOR_METAFORMAT_C_STRING, |
533 | "text/plain", | 632 | "text/plain", |
534 | this.title, | 633 | this.title, |
535 | slen + 1)) ) || | 634 | slen + 1)) ) || |
536 | ( (this.author != NULL) && | 635 | ( (this.author != NULL) && |
537 | (0 < (slen = strlen(this.author))) && | 636 | (0 < (slen = strlen (this.author))) && |
538 | (0 != proc (proc_cls, | 637 | (0 != proc (proc_cls, |
539 | "asf", | 638 | "asf", |
540 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 639 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
541 | EXTRACTOR_METAFORMAT_C_STRING, | 640 | EXTRACTOR_METAFORMAT_C_STRING, |
542 | "text/plain", | 641 | "text/plain", |
543 | this.author, | 642 | this.author, |
544 | slen + 1)) ) || | 643 | slen + 1)) ) || |
545 | ( (this.comment != NULL) && | 644 | ( (this.comment != NULL) && |
546 | (0 < (slen = strlen(this.comment))) && | 645 | (0 < (slen = strlen (this.comment))) && |
547 | (0 != proc (proc_cls, | 646 | (0 != proc (proc_cls, |
548 | "asf", | 647 | "asf", |
549 | EXTRACTOR_METATYPE_COMMENT, | 648 | EXTRACTOR_METATYPE_COMMENT, |
550 | EXTRACTOR_METAFORMAT_C_STRING, | 649 | EXTRACTOR_METAFORMAT_C_STRING, |
551 | "text/plain", | 650 | "text/plain", |
552 | this.comment, | 651 | this.comment, |
553 | slen + 1)) ) || | 652 | slen + 1)) ) || |
554 | ( (this.copyright != NULL) && | 653 | ( (this.copyright != NULL) && |
555 | (0 < (slen = strlen(this.copyright))) && | 654 | (0 < (slen = strlen (this.copyright))) && |
556 | (0 != proc (proc_cls, | 655 | (0 != proc (proc_cls, |
557 | "asf", | 656 | "asf", |
558 | EXTRACTOR_METATYPE_COPYRIGHT, | 657 | EXTRACTOR_METATYPE_COPYRIGHT, |
559 | EXTRACTOR_METAFORMAT_C_STRING, | 658 | EXTRACTOR_METAFORMAT_C_STRING, |
560 | "text/plain", | 659 | "text/plain", |
561 | this.copyright, | 660 | this.copyright, |
562 | slen + 1)) ) || | 661 | slen + 1)) ) || |
563 | (0 != proc (proc_cls, | 662 | (0 != proc (proc_cls, |
564 | "asf", | 663 | "asf", |
565 | EXTRACTOR_METATYPE_MIMETYPE, | 664 | EXTRACTOR_METATYPE_MIMETYPE, |
566 | EXTRACTOR_METAFORMAT_C_STRING, | 665 | EXTRACTOR_METAFORMAT_C_STRING, |
567 | "text/plain", | 666 | "text/plain", |
568 | "video/x-ms-asf", | 667 | "video/x-ms-asf", |
569 | strlen("video/x-ms-asf") + 1)) || | 668 | strlen ("video/x-ms-asf") + 1)) || |
570 | (0 != proc (proc_cls, | 669 | (0 != proc (proc_cls, |
571 | "asf", | 670 | "asf", |
572 | EXTRACTOR_METATYPE_DURATION, | 671 | EXTRACTOR_METATYPE_DURATION, |
573 | EXTRACTOR_METAFORMAT_C_STRING, | 672 | EXTRACTOR_METAFORMAT_C_STRING, |
574 | "text/plain", | 673 | "text/plain", |
575 | duration_str, | 674 | duration_str, |
576 | strlen(duration_str) + 1)) ) | 675 | strlen (duration_str) + 1)) ) |
577 | ret = 1; | 676 | ret = 1; |
578 | } | 677 | } |
579 | free (this.title); | 678 | free (this.title); |
580 | free (this.author); | 679 | free (this.author); |
@@ -584,4 +683,5 @@ EXTRACTOR_asf_extract (const char *data, | |||
584 | return ret; | 683 | return ret; |
585 | } | 684 | } |
586 | 685 | ||
686 | |||
587 | /* end of asf_extractor.c */ | 687 | /* end of asf_extractor.c */ |
diff --git a/src/plugins/old/convert_numeric.c b/src/plugins/old/convert_numeric.c index b345014..35bd65a 100644 --- a/src/plugins/old/convert_numeric.c +++ b/src/plugins/old/convert_numeric.c | |||
@@ -61,45 +61,44 @@ static unsigned long get_field (const unsigned char *, | |||
61 | unsigned int, | 61 | unsigned int, |
62 | unsigned int, | 62 | unsigned int, |
63 | unsigned int); | 63 | unsigned int); |
64 | |||
64 | static int floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt, | 65 | static int floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt, |
65 | const void *from); | 66 | const void *from); |
66 | 67 | ||
67 | static int | 68 | static int |
68 | floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt /*ATTRIBUTE_UNUSED*/, | 69 | floatformat_always_valid (const struct |
70 | EXTRACTOR_floatformat *fmt /*ATTRIBUTE_UNUSED*/, | ||
69 | const void *from /*ATTRIBUTE_UNUSED*/) | 71 | const void *from /*ATTRIBUTE_UNUSED*/) |
70 | { | 72 | { |
71 | return 1; | 73 | return 1; |
72 | } | 74 | } |
73 | 75 | ||
76 | |||
74 | /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not | 77 | /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not |
75 | going to bother with trying to muck around with whether it is defined in | 78 | going to bother with trying to muck around with whether it is defined in |
76 | a system header, what we do if not, etc. */ | 79 | a system header, what we do if not, etc. */ |
77 | #define FLOATFORMAT_CHAR_BIT 8 | 80 | #define FLOATFORMAT_CHAR_BIT 8 |
78 | 81 | ||
79 | /* floatformats for IEEE single and double, big and little endian. */ | 82 | /* floatformats for IEEE single and double, big and little endian. */ |
80 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big = | 83 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big = { |
81 | { | ||
82 | floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23, | 84 | floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23, |
83 | floatformat_intbit_no, | 85 | floatformat_intbit_no, |
84 | "floatformat_ieee_single_big", | 86 | "floatformat_ieee_single_big", |
85 | floatformat_always_valid | 87 | floatformat_always_valid |
86 | }; | 88 | }; |
87 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_little = | 89 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_little = { |
88 | { | ||
89 | floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23, | 90 | floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23, |
90 | floatformat_intbit_no, | 91 | floatformat_intbit_no, |
91 | "floatformat_ieee_single_little", | 92 | "floatformat_ieee_single_little", |
92 | floatformat_always_valid | 93 | floatformat_always_valid |
93 | }; | 94 | }; |
94 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big = | 95 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big = { |
95 | { | ||
96 | floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52, | 96 | floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52, |
97 | floatformat_intbit_no, | 97 | floatformat_intbit_no, |
98 | "floatformat_ieee_double_big", | 98 | "floatformat_ieee_double_big", |
99 | floatformat_always_valid | 99 | floatformat_always_valid |
100 | }; | 100 | }; |
101 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little = | 101 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little = { |
102 | { | ||
103 | floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52, | 102 | floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52, |
104 | floatformat_intbit_no, | 103 | floatformat_intbit_no, |
105 | "floatformat_ieee_double_little", | 104 | "floatformat_ieee_double_little", |
@@ -109,8 +108,8 @@ const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little = | |||
109 | /* floatformat for IEEE double, little endian byte order, with big endian word | 108 | /* floatformat for IEEE double, little endian byte order, with big endian word |
110 | ordering, as on the ARM. */ | 109 | ordering, as on the ARM. */ |
111 | 110 | ||
112 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_littlebyte_bigword = | 111 | const struct EXTRACTOR_floatformat |
113 | { | 112 | EXTRACTOR_floatformat_ieee_double_littlebyte_bigword = { |
114 | floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52, | 113 | floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52, |
115 | floatformat_intbit_no, | 114 | floatformat_intbit_no, |
116 | "floatformat_ieee_double_littlebyte_bigword", | 115 | "floatformat_ieee_double_littlebyte_bigword", |
@@ -119,33 +118,32 @@ const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_littlebyte_ | |||
119 | 118 | ||
120 | /* floatformat for VAX. Not quite IEEE, but close enough. */ | 119 | /* floatformat for VAX. Not quite IEEE, but close enough. */ |
121 | 120 | ||
122 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f = | 121 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f = { |
123 | { | ||
124 | floatformat_vax, 32, 0, 1, 8, 129, 0, 9, 23, | 122 | floatformat_vax, 32, 0, 1, 8, 129, 0, 9, 23, |
125 | floatformat_intbit_no, | 123 | floatformat_intbit_no, |
126 | "floatformat_vax_f", | 124 | "floatformat_vax_f", |
127 | floatformat_always_valid | 125 | floatformat_always_valid |
128 | }; | 126 | }; |
129 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d = | 127 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d = { |
130 | { | ||
131 | floatformat_vax, 64, 0, 1, 8, 129, 0, 9, 55, | 128 | floatformat_vax, 64, 0, 1, 8, 129, 0, 9, 55, |
132 | floatformat_intbit_no, | 129 | floatformat_intbit_no, |
133 | "floatformat_vax_d", | 130 | "floatformat_vax_d", |
134 | floatformat_always_valid | 131 | floatformat_always_valid |
135 | }; | 132 | }; |
136 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g = | 133 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g = { |
137 | { | ||
138 | floatformat_vax, 64, 0, 1, 11, 1025, 0, 12, 52, | 134 | floatformat_vax, 64, 0, 1, 11, 1025, 0, 12, 52, |
139 | floatformat_intbit_no, | 135 | floatformat_intbit_no, |
140 | "floatformat_vax_g", | 136 | "floatformat_vax_g", |
141 | floatformat_always_valid | 137 | floatformat_always_valid |
142 | }; | 138 | }; |
143 | 139 | ||
144 | static int floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, | 140 | static int floatformat_i387_ext_is_valid (const struct |
145 | const void *from); | 141 | EXTRACTOR_floatformat *fmt, |
142 | const void *from); | ||
146 | 143 | ||
147 | static int | 144 | static int |
148 | floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const void *from) | 145 | floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const |
146 | void *from) | ||
149 | { | 147 | { |
150 | /* In the i387 double-extended format, if the exponent is all ones, | 148 | /* In the i387 double-extended format, if the exponent is all ones, |
151 | then the integer bit must be set. If the exponent is neither 0 | 149 | then the integer bit must be set. If the exponent is neither 0 |
@@ -155,9 +153,9 @@ floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const vo | |||
155 | const unsigned char *ufrom = (const unsigned char *) from; | 153 | const unsigned char *ufrom = (const unsigned char *) from; |
156 | 154 | ||
157 | exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, | 155 | exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, |
158 | fmt->exp_start, fmt->exp_len); | 156 | fmt->exp_start, fmt->exp_len); |
159 | int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize, | 157 | int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize, |
160 | fmt->man_start, 1); | 158 | fmt->man_start, 1); |
161 | 159 | ||
162 | if ((exponent == 0) != (int_bit == 0)) | 160 | if ((exponent == 0) != (int_bit == 0)) |
163 | return 0; | 161 | return 0; |
@@ -165,38 +163,34 @@ floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const vo | |||
165 | return 1; | 163 | return 1; |
166 | } | 164 | } |
167 | 165 | ||
168 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext = | 166 | |
169 | { | 167 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext = { |
170 | floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, | 168 | floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, |
171 | floatformat_intbit_yes, | 169 | floatformat_intbit_yes, |
172 | "floatformat_i387_ext", | 170 | "floatformat_i387_ext", |
173 | floatformat_i387_ext_is_valid | 171 | floatformat_i387_ext_is_valid |
174 | }; | 172 | }; |
175 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext = | 173 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext = { |
176 | { | ||
177 | /* Note that the bits from 16 to 31 are unused. */ | 174 | /* Note that the bits from 16 to 31 are unused. */ |
178 | floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64, | 175 | floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64, |
179 | floatformat_intbit_yes, | 176 | floatformat_intbit_yes, |
180 | "floatformat_m68881_ext", | 177 | "floatformat_m68881_ext", |
181 | floatformat_always_valid | 178 | floatformat_always_valid |
182 | }; | 179 | }; |
183 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext = | 180 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext = { |
184 | { | ||
185 | /* Note that the bits from 0 to 15 are unused. */ | 181 | /* Note that the bits from 0 to 15 are unused. */ |
186 | floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64, | 182 | floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64, |
187 | floatformat_intbit_yes, | 183 | floatformat_intbit_yes, |
188 | "floatformat_i960_ext", | 184 | "floatformat_i960_ext", |
189 | floatformat_always_valid | 185 | floatformat_always_valid |
190 | }; | 186 | }; |
191 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext = | 187 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext = { |
192 | { | ||
193 | floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, | 188 | floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, |
194 | floatformat_intbit_yes, | 189 | floatformat_intbit_yes, |
195 | "floatformat_m88110_ext", | 190 | "floatformat_m88110_ext", |
196 | floatformat_always_valid | 191 | floatformat_always_valid |
197 | }; | 192 | }; |
198 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext = | 193 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext = { |
199 | { | ||
200 | /* Harris uses raw format 128 bytes long, but the number is just an ieee | 194 | /* Harris uses raw format 128 bytes long, but the number is just an ieee |
201 | double, and the last 64 bits are wasted. */ | 195 | double, and the last 64 bits are wasted. */ |
202 | floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52, | 196 | floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52, |
@@ -204,45 +198,40 @@ const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext = | |||
204 | "floatformat_m88110_ext_harris", | 198 | "floatformat_m88110_ext_harris", |
205 | floatformat_always_valid | 199 | floatformat_always_valid |
206 | }; | 200 | }; |
207 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big = | 201 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big = { |
208 | { | ||
209 | /* Bits 1 to 16 are unused. */ | 202 | /* Bits 1 to 16 are unused. */ |
210 | floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, | 203 | floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, |
211 | floatformat_intbit_yes, | 204 | floatformat_intbit_yes, |
212 | "floatformat_arm_ext_big", | 205 | "floatformat_arm_ext_big", |
213 | floatformat_always_valid | 206 | floatformat_always_valid |
214 | }; | 207 | }; |
215 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_littlebyte_bigword = | 208 | const struct EXTRACTOR_floatformat |
216 | { | 209 | EXTRACTOR_floatformat_arm_ext_littlebyte_bigword = { |
217 | /* Bits 1 to 16 are unused. */ | 210 | /* Bits 1 to 16 are unused. */ |
218 | floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, | 211 | floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, |
219 | floatformat_intbit_yes, | 212 | floatformat_intbit_yes, |
220 | "floatformat_arm_ext_littlebyte_bigword", | 213 | "floatformat_arm_ext_littlebyte_bigword", |
221 | floatformat_always_valid | 214 | floatformat_always_valid |
222 | }; | 215 | }; |
223 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big = | 216 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big = { |
224 | { | ||
225 | floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64, | 217 | floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64, |
226 | floatformat_intbit_yes, | 218 | floatformat_intbit_yes, |
227 | "floatformat_ia64_spill_big", | 219 | "floatformat_ia64_spill_big", |
228 | floatformat_always_valid | 220 | floatformat_always_valid |
229 | }; | 221 | }; |
230 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_little = | 222 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_little = { |
231 | { | ||
232 | floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64, | 223 | floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64, |
233 | floatformat_intbit_yes, | 224 | floatformat_intbit_yes, |
234 | "floatformat_ia64_spill_little", | 225 | "floatformat_ia64_spill_little", |
235 | floatformat_always_valid | 226 | floatformat_always_valid |
236 | }; | 227 | }; |
237 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big = | 228 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big = { |
238 | { | ||
239 | floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112, | 229 | floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112, |
240 | floatformat_intbit_no, | 230 | floatformat_intbit_no, |
241 | "floatformat_ia64_quad_big", | 231 | "floatformat_ia64_quad_big", |
242 | floatformat_always_valid | 232 | floatformat_always_valid |
243 | }; | 233 | }; |
244 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little = | 234 | const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little = { |
245 | { | ||
246 | floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112, | 235 | floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112, |
247 | floatformat_intbit_no, | 236 | floatformat_intbit_no, |
248 | "floatformat_ia64_quad_little", | 237 | "floatformat_ia64_quad_little", |
@@ -257,7 +246,8 @@ const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little = | |||
257 | /* Extract a field which starts at START and is LEN bits long. DATA and | 246 | /* Extract a field which starts at START and is LEN bits long. DATA and |
258 | TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */ | 247 | TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */ |
259 | static unsigned long | 248 | static unsigned long |
260 | get_field (const unsigned char *data, enum EXTRACTOR_floatformat_byteorders order, | 249 | get_field (const unsigned char *data, enum EXTRACTOR_floatformat_byteorders |
250 | order, | ||
261 | unsigned int total_len, unsigned int start, unsigned int len) | 251 | unsigned int total_len, unsigned int start, unsigned int len) |
262 | { | 252 | { |
263 | unsigned long result = 0; | 253 | unsigned long result = 0; |
@@ -278,29 +268,30 @@ get_field (const unsigned char *data, enum EXTRACTOR_floatformat_byteorders orde | |||
278 | hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); | 268 | hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); |
279 | 269 | ||
280 | do | 270 | do |
281 | { | 271 | { |
282 | unsigned int shifted = *(data + cur_byte) >> lo_bit; | 272 | unsigned int shifted = *(data + cur_byte) >> lo_bit; |
283 | unsigned int bits = hi_bit - lo_bit; | 273 | unsigned int bits = hi_bit - lo_bit; |
284 | unsigned int mask = (1 << bits) - 1; | 274 | unsigned int mask = (1 << bits) - 1; |
285 | result |= (shifted & mask) << cur_bitshift; | 275 | result |= (shifted & mask) << cur_bitshift; |
286 | len -= bits; | 276 | len -= bits; |
287 | cur_bitshift += bits; | 277 | cur_bitshift += bits; |
288 | cur_byte += nextbyte; | 278 | cur_byte += nextbyte; |
289 | lo_bit = 0; | 279 | lo_bit = 0; |
290 | hi_bit = min (len, FLOATFORMAT_CHAR_BIT); | 280 | hi_bit = min (len, FLOATFORMAT_CHAR_BIT); |
291 | } | 281 | } |
292 | while (len != 0); | 282 | while (len != 0); |
293 | 283 | ||
294 | return result; | 284 | return result; |
295 | } | 285 | } |
296 | 286 | ||
287 | |||
297 | /* Convert from FMT to a double. | 288 | /* Convert from FMT to a double. |
298 | FROM is the address of the extended float. | 289 | FROM is the address of the extended float. |
299 | Store the double in *TO. */ | 290 | Store the double in *TO. */ |
300 | 291 | ||
301 | void | 292 | void |
302 | EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt, | 293 | EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt, |
303 | const void *from, double *to) | 294 | const void *from, double *to) |
304 | { | 295 | { |
305 | const unsigned char *ufrom = (const unsigned char *) from; | 296 | const unsigned char *ufrom = (const unsigned char *) from; |
306 | double dto; | 297 | double dto; |
@@ -308,65 +299,65 @@ EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt, | |||
308 | unsigned long mant; | 299 | unsigned long mant; |
309 | unsigned int mant_bits, mant_off; | 300 | unsigned int mant_bits, mant_off; |
310 | int mant_bits_left; | 301 | int mant_bits_left; |
311 | int special_exponent; /* It's a NaN, denorm or zero */ | 302 | int special_exponent; /* It's a NaN, denorm or zero */ |
312 | 303 | ||
313 | exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, | 304 | exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, |
314 | fmt->exp_start, fmt->exp_len); | 305 | fmt->exp_start, fmt->exp_len); |
315 | 306 | ||
316 | /* If the exponent indicates a NaN, we don't have information to | 307 | /* If the exponent indicates a NaN, we don't have information to |
317 | decide what to do. So we handle it like IEEE, except that we | 308 | decide what to do. So we handle it like IEEE, except that we |
318 | don't try to preserve the type of NaN. FIXME. */ | 309 | don't try to preserve the type of NaN. FIXME. */ |
319 | if ((unsigned long) exponent == fmt->exp_nan) | 310 | if ((unsigned long) exponent == fmt->exp_nan) |
311 | { | ||
312 | int nan; | ||
313 | |||
314 | mant_off = fmt->man_start; | ||
315 | mant_bits_left = fmt->man_len; | ||
316 | nan = 0; | ||
317 | while (mant_bits_left > 0) | ||
320 | { | 318 | { |
321 | int nan; | 319 | mant_bits = min (mant_bits_left, 32); |
322 | 320 | ||
323 | mant_off = fmt->man_start; | 321 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, |
324 | mant_bits_left = fmt->man_len; | 322 | mant_off, mant_bits) != 0) |
325 | nan = 0; | 323 | { |
326 | while (mant_bits_left > 0) | 324 | /* This is a NaN. */ |
327 | { | 325 | nan = 1; |
328 | mant_bits = min (mant_bits_left, 32); | 326 | break; |
329 | 327 | } | |
330 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, | 328 | |
331 | mant_off, mant_bits) != 0) | 329 | mant_off += mant_bits; |
332 | { | 330 | mant_bits_left -= mant_bits; |
333 | /* This is a NaN. */ | ||
334 | nan = 1; | ||
335 | break; | ||
336 | } | ||
337 | |||
338 | mant_off += mant_bits; | ||
339 | mant_bits_left -= mant_bits; | ||
340 | } | ||
341 | |||
342 | /* On certain systems (such as GNU/Linux), the use of the | ||
343 | INFINITY macro below may generate a warning that can not be | ||
344 | silenced due to a bug in GCC (PR preprocessor/11931). The | ||
345 | preprocessor fails to recognise the __extension__ keyword in | ||
346 | conjunction with the GNU/C99 extension for hexadecimal | ||
347 | floating point constants and will issue a warning when | ||
348 | compiling with -pedantic. */ | ||
349 | if (nan) | ||
350 | dto = NAN; | ||
351 | else | ||
352 | dto = INFINITY; | ||
353 | |||
354 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) | ||
355 | dto = -dto; | ||
356 | |||
357 | *to = dto; | ||
358 | |||
359 | return; | ||
360 | } | 331 | } |
361 | 332 | ||
333 | /* On certain systems (such as GNU/Linux), the use of the | ||
334 | INFINITY macro below may generate a warning that can not be | ||
335 | silenced due to a bug in GCC (PR preprocessor/11931). The | ||
336 | preprocessor fails to recognise the __extension__ keyword in | ||
337 | conjunction with the GNU/C99 extension for hexadecimal | ||
338 | floating point constants and will issue a warning when | ||
339 | compiling with -pedantic. */if (nan) | ||
340 | dto = NAN; | ||
341 | else | ||
342 | dto = INFINITY; | ||
343 | |||
344 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) | ||
345 | dto = -dto; | ||
346 | |||
347 | *to = dto; | ||
348 | |||
349 | return; | ||
350 | } | ||
351 | |||
362 | mant_bits_left = fmt->man_len; | 352 | mant_bits_left = fmt->man_len; |
363 | mant_off = fmt->man_start; | 353 | mant_off = fmt->man_start; |
364 | dto = 0.0; | 354 | dto = 0.0; |
365 | 355 | ||
366 | special_exponent = (exponent == 0) || ((unsigned long) exponent == fmt->exp_nan); | 356 | special_exponent = (exponent == 0) || ((unsigned long) exponent == |
357 | fmt->exp_nan); | ||
367 | 358 | ||
368 | /* Don't bias zero's, denorms or NaNs. */ | 359 | /* Don't bias zero's, denorms or NaNs. */ |
369 | if (!special_exponent) | 360 | if (! special_exponent) |
370 | exponent -= fmt->exp_bias; | 361 | exponent -= fmt->exp_bias; |
371 | 362 | ||
372 | /* Build the result algebraically. Might go infinite, underflow, etc; | 363 | /* Build the result algebraically. Might go infinite, underflow, etc; |
@@ -375,36 +366,36 @@ EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt, | |||
375 | /* If this format uses a hidden bit, explicitly add it in now. Otherwise, | 366 | /* If this format uses a hidden bit, explicitly add it in now. Otherwise, |
376 | increment the exponent by one to account for the integer bit. */ | 367 | increment the exponent by one to account for the integer bit. */ |
377 | 368 | ||
378 | if (!special_exponent) | 369 | if (! special_exponent) |
379 | { | 370 | { |
380 | if (fmt->intbit == floatformat_intbit_no) | 371 | if (fmt->intbit == floatformat_intbit_no) |
381 | dto = ldexp (1.0, exponent); | 372 | dto = ldexp (1.0, exponent); |
382 | else | 373 | else |
383 | exponent++; | 374 | exponent++; |
384 | } | 375 | } |
385 | 376 | ||
386 | while (mant_bits_left > 0) | 377 | while (mant_bits_left > 0) |
387 | { | 378 | { |
388 | mant_bits = min (mant_bits_left, 32); | 379 | mant_bits = min (mant_bits_left, 32); |
389 | 380 | ||
390 | mant = get_field (ufrom, fmt->byteorder, fmt->totalsize, | 381 | mant = get_field (ufrom, fmt->byteorder, fmt->totalsize, |
391 | mant_off, mant_bits); | 382 | mant_off, mant_bits); |
392 | 383 | ||
393 | /* Handle denormalized numbers. FIXME: What should we do for | 384 | /* Handle denormalized numbers. FIXME: What should we do for |
394 | non-IEEE formats? */ | 385 | non-IEEE formats? */ |
395 | if (special_exponent && exponent == 0 && mant != 0) | 386 | if (special_exponent && (exponent == 0) && (mant != 0) ) |
396 | dto += ldexp ((double)mant, | 387 | dto += ldexp ((double) mant, |
397 | (- fmt->exp_bias | 388 | (-fmt->exp_bias |
398 | - mant_bits | 389 | - mant_bits |
399 | - (mant_off - fmt->man_start) | 390 | - (mant_off - fmt->man_start) |
400 | + 1)); | 391 | + 1)); |
401 | else | 392 | else |
402 | dto += ldexp ((double)mant, exponent - mant_bits); | 393 | dto += ldexp ((double) mant, exponent - mant_bits); |
403 | if (exponent != 0) | 394 | if (exponent != 0) |
404 | exponent -= mant_bits; | 395 | exponent -= mant_bits; |
405 | mant_off += mant_bits; | 396 | mant_off += mant_bits; |
406 | mant_bits_left -= mant_bits; | 397 | mant_bits_left -= mant_bits; |
407 | } | 398 | } |
408 | 399 | ||
409 | /* Negate it if negative. */ | 400 | /* Negate it if negative. */ |
410 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) | 401 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) |
@@ -412,6 +403,7 @@ EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt, | |||
412 | *to = dto; | 403 | *to = dto; |
413 | } | 404 | } |
414 | 405 | ||
406 | |||
415 | static void put_field (unsigned char *, enum EXTRACTOR_floatformat_byteorders, | 407 | static void put_field (unsigned char *, enum EXTRACTOR_floatformat_byteorders, |
416 | unsigned int, | 408 | unsigned int, |
417 | unsigned int, | 409 | unsigned int, |
@@ -442,27 +434,29 @@ put_field (unsigned char *data, enum EXTRACTOR_floatformat_byteorders order, | |||
442 | hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); | 434 | hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); |
443 | 435 | ||
444 | do | 436 | do |
445 | { | 437 | { |
446 | unsigned char *byte_ptr = data + cur_byte; | 438 | unsigned char *byte_ptr = data + cur_byte; |
447 | unsigned int bits = hi_bit - lo_bit; | 439 | unsigned int bits = hi_bit - lo_bit; |
448 | unsigned int mask = ((1 << bits) - 1) << lo_bit; | 440 | unsigned int mask = ((1 << bits) - 1) << lo_bit; |
449 | *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask); | 441 | *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask); |
450 | stuff_to_put >>= bits; | 442 | stuff_to_put >>= bits; |
451 | len -= bits; | 443 | len -= bits; |
452 | cur_byte += nextbyte; | 444 | cur_byte += nextbyte; |
453 | lo_bit = 0; | 445 | lo_bit = 0; |
454 | hi_bit = min (len, FLOATFORMAT_CHAR_BIT); | 446 | hi_bit = min (len, FLOATFORMAT_CHAR_BIT); |
455 | } | 447 | } |
456 | while (len != 0); | 448 | while (len != 0); |
457 | } | 449 | } |
458 | 450 | ||
451 | |||
459 | /* The converse: convert the double *FROM to an extended float | 452 | /* The converse: convert the double *FROM to an extended float |
460 | and store where TO points. Neither FROM nor TO have any alignment | 453 | and store where TO points. Neither FROM nor TO have any alignment |
461 | restrictions. */ | 454 | restrictions. */ |
462 | 455 | ||
463 | void | 456 | void |
464 | EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *fmt, | 457 | EXTRACTOR_common_floatformat_from_double (const struct |
465 | const double *from, void *to) | 458 | EXTRACTOR_floatformat *fmt, |
459 | const double *from, void *to) | ||
466 | { | 460 | { |
467 | double dfrom; | 461 | double dfrom; |
468 | int exponent; | 462 | int exponent; |
@@ -476,88 +470,90 @@ EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *fm | |||
476 | 470 | ||
477 | /* If negative, set the sign bit. */ | 471 | /* If negative, set the sign bit. */ |
478 | if (dfrom < 0) | 472 | if (dfrom < 0) |
479 | { | 473 | { |
480 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1); | 474 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1); |
481 | dfrom = -dfrom; | 475 | dfrom = -dfrom; |
482 | } | 476 | } |
483 | 477 | ||
484 | if (dfrom == 0) | 478 | if (dfrom == 0) |
485 | { | 479 | { |
486 | /* 0.0. */ | 480 | /* 0.0. */ |
487 | return; | 481 | return; |
488 | } | 482 | } |
489 | 483 | ||
490 | if (dfrom != dfrom) | 484 | if (dfrom != dfrom) |
491 | { | 485 | { |
492 | /* NaN. */ | 486 | /* NaN. */ |
493 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, | 487 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, |
494 | fmt->exp_len, fmt->exp_nan); | 488 | fmt->exp_len, fmt->exp_nan); |
495 | /* Be sure it's not infinity, but NaN value is irrelevant. */ | 489 | /* Be sure it's not infinity, but NaN value is irrelevant. */ |
496 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start, | 490 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start, |
497 | 32, 1); | 491 | 32, 1); |
498 | return; | 492 | return; |
499 | } | 493 | } |
500 | 494 | ||
501 | if (dfrom + dfrom == dfrom) | 495 | if (dfrom + dfrom == dfrom) |
502 | { | 496 | { |
503 | /* This can only happen for an infinite value (or zero, which we | 497 | /* This can only happen for an infinite value (or zero, which we |
504 | already handled above). */ | 498 | already handled above). */ |
505 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, | 499 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, |
506 | fmt->exp_len, fmt->exp_nan); | 500 | fmt->exp_len, fmt->exp_nan); |
507 | return; | 501 | return; |
508 | } | 502 | } |
509 | 503 | ||
510 | mant = frexp (dfrom, &exponent); | 504 | mant = frexp (dfrom, &exponent); |
511 | if (exponent + fmt->exp_bias - 1 > 0) | 505 | if (exponent + fmt->exp_bias - 1 > 0) |
512 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, | 506 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, |
513 | fmt->exp_len, exponent + fmt->exp_bias - 1); | 507 | fmt->exp_len, exponent + fmt->exp_bias - 1); |
514 | else | 508 | else |
515 | { | 509 | { |
516 | /* Handle a denormalized number. FIXME: What should we do for | 510 | /* Handle a denormalized number. FIXME: What should we do for |
517 | non-IEEE formats? */ | 511 | non-IEEE formats? */ |
518 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, | 512 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, |
519 | fmt->exp_len, 0); | 513 | fmt->exp_len, 0); |
520 | mant = ldexp (mant, exponent + fmt->exp_bias - 1); | 514 | mant = ldexp (mant, exponent + fmt->exp_bias - 1); |
521 | } | 515 | } |
522 | 516 | ||
523 | mant_bits_left = fmt->man_len; | 517 | mant_bits_left = fmt->man_len; |
524 | mant_off = fmt->man_start; | 518 | mant_off = fmt->man_start; |
525 | while (mant_bits_left > 0) | 519 | while (mant_bits_left > 0) |
520 | { | ||
521 | unsigned long mant_long; | ||
522 | mant_bits = mant_bits_left < 32 ? mant_bits_left : 32; | ||
523 | |||
524 | mant *= 4294967296.0; | ||
525 | mant_long = (unsigned long) mant; | ||
526 | mant -= mant_long; | ||
527 | |||
528 | /* If the integer bit is implicit, and we are not creating a | ||
529 | denormalized number, then we need to discard it. */ | ||
530 | if (( (unsigned int) mant_bits_left == fmt->man_len) | ||
531 | && (fmt->intbit == floatformat_intbit_no) | ||
532 | && (exponent + fmt->exp_bias - 1 > 0) ) | ||
526 | { | 533 | { |
527 | unsigned long mant_long; | 534 | mant_long &= 0x7fffffff; |
528 | mant_bits = mant_bits_left < 32 ? mant_bits_left : 32; | 535 | mant_bits -= 1; |
529 | |||
530 | mant *= 4294967296.0; | ||
531 | mant_long = (unsigned long)mant; | ||
532 | mant -= mant_long; | ||
533 | |||
534 | /* If the integer bit is implicit, and we are not creating a | ||
535 | denormalized number, then we need to discard it. */ | ||
536 | if ((unsigned int) mant_bits_left == fmt->man_len | ||
537 | && fmt->intbit == floatformat_intbit_no | ||
538 | && exponent + fmt->exp_bias - 1 > 0) | ||
539 | { | ||
540 | mant_long &= 0x7fffffff; | ||
541 | mant_bits -= 1; | ||
542 | } | ||
543 | else if (mant_bits < 32) | ||
544 | { | ||
545 | /* The bits we want are in the most significant MANT_BITS bits of | ||
546 | mant_long. Move them to the least significant. */ | ||
547 | mant_long >>= 32 - mant_bits; | ||
548 | } | ||
549 | |||
550 | put_field (uto, fmt->byteorder, fmt->totalsize, | ||
551 | mant_off, mant_bits, mant_long); | ||
552 | mant_off += mant_bits; | ||
553 | mant_bits_left -= mant_bits; | ||
554 | } | 536 | } |
537 | else if (mant_bits < 32) | ||
538 | { | ||
539 | /* The bits we want are in the most significant MANT_BITS bits of | ||
540 | mant_long. Move them to the least significant. */ | ||
541 | mant_long >>= 32 - mant_bits; | ||
542 | } | ||
543 | |||
544 | put_field (uto, fmt->byteorder, fmt->totalsize, | ||
545 | mant_off, mant_bits, mant_long); | ||
546 | mant_off += mant_bits; | ||
547 | mant_bits_left -= mant_bits; | ||
548 | } | ||
555 | } | 549 | } |
556 | 550 | ||
551 | |||
557 | /* Return non-zero iff the data at FROM is a valid number in format FMT. */ | 552 | /* Return non-zero iff the data at FROM is a valid number in format FMT. */ |
558 | 553 | ||
559 | int | 554 | int |
560 | EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt, const void *from) | 555 | EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt, |
556 | const void *from) | ||
561 | { | 557 | { |
562 | return fmt->is_valid (fmt, from); | 558 | return fmt->is_valid (fmt, from); |
563 | } | 559 | } |
@@ -575,15 +571,15 @@ ieee_test (double n) | |||
575 | double result; | 571 | double result; |
576 | 572 | ||
577 | floatformat_to_double (&floatformat_ieee_double_little, &n, &result); | 573 | floatformat_to_double (&floatformat_ieee_double_little, &n, &result); |
578 | if ((n != result && (! isnan (n) || ! isnan (result))) | 574 | if (((n != result) && (! isnan (n) || ! isnan (result))) |
579 | || (n < 0 && result >= 0) | 575 | || ((n < 0) && (result >= 0)) |
580 | || (n >= 0 && result < 0)) | 576 | || ((n >= 0) && (result < 0))) |
581 | printf ("Differ(to): %.20g -> %.20g\n", n, result); | 577 | printf ("Differ(to): %.20g -> %.20g\n", n, result); |
582 | 578 | ||
583 | floatformat_from_double (&floatformat_ieee_double_little, &n, &result); | 579 | floatformat_from_double (&floatformat_ieee_double_little, &n, &result); |
584 | if ((n != result && (! isnan (n) || ! isnan (result))) | 580 | if (((n != result) && (! isnan (n) || ! isnan (result))) |
585 | || (n < 0 && result >= 0) | 581 | || ((n < 0) && (result >= 0)) |
586 | || (n >= 0 && result < 0)) | 582 | || ((n >= 0) && (result < 0))) |
587 | printf ("Differ(from): %.20g -> %.20g\n", n, result); | 583 | printf ("Differ(from): %.20g -> %.20g\n", n, result); |
588 | 584 | ||
589 | #if 0 | 585 | #if 0 |
@@ -600,13 +596,14 @@ ieee_test (double n) | |||
600 | #if IEEE_DEBUG > 1 | 596 | #if IEEE_DEBUG > 1 |
601 | /* This is to be run on a host which uses 68881 format. */ | 597 | /* This is to be run on a host which uses 68881 format. */ |
602 | { | 598 | { |
603 | long double ex = *(long double *)exten; | 599 | long double ex = *(long double *) exten; |
604 | if (ex != n) | 600 | if (ex != n) |
605 | printf ("Differ(from vs. extended): %.20g\n", n); | 601 | printf ("Differ(from vs. extended): %.20g\n", n); |
606 | } | 602 | } |
607 | #endif | 603 | #endif |
608 | } | 604 | } |
609 | 605 | ||
606 | |||
610 | int | 607 | int |
611 | main (void) | 608 | main (void) |
612 | { | 609 | { |
@@ -620,12 +617,14 @@ main (void) | |||
620 | ieee_test (1.2E-70); | 617 | ieee_test (1.2E-70); |
621 | ieee_test (1.2E-316); | 618 | ieee_test (1.2E-316); |
622 | ieee_test (4.9406564584124654E-324); | 619 | ieee_test (4.9406564584124654E-324); |
623 | ieee_test (- 4.9406564584124654E-324); | 620 | ieee_test (-4.9406564584124654E-324); |
624 | ieee_test (- 0.0); | 621 | ieee_test (-0.0); |
625 | ieee_test (- INFINITY); | 622 | ieee_test (-INFINITY); |
626 | ieee_test (- NAN); | 623 | ieee_test (-NAN); |
627 | ieee_test (INFINITY); | 624 | ieee_test (INFINITY); |
628 | ieee_test (NAN); | 625 | ieee_test (NAN); |
629 | return 0; | 626 | return 0; |
630 | } | 627 | } |
628 | |||
629 | |||
631 | #endif | 630 | #endif |
diff --git a/src/plugins/old/convert_numeric.h b/src/plugins/old/convert_numeric.h index cc425f5..f3adead 100644 --- a/src/plugins/old/convert_numeric.h +++ b/src/plugins/old/convert_numeric.h | |||
@@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License | |||
18 | along with this program; if not, write to the Free Software | 18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ | 19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
20 | 20 | ||
21 | #if !defined (FLOATFORMAT_H) | 21 | #if ! defined (FLOATFORMAT_H) |
22 | #define FLOATFORMAT_H 1 | 22 | #define FLOATFORMAT_H 1 |
23 | 23 | ||
24 | /*#include "ansidecl.h"*/ | 24 | /*#include "ansidecl.h"*/ |
@@ -31,7 +31,8 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. | |||
31 | 31 | ||
32 | /* What is the order of the bytes? */ | 32 | /* What is the order of the bytes? */ |
33 | 33 | ||
34 | enum EXTRACTOR_floatformat_byteorders { | 34 | enum EXTRACTOR_floatformat_byteorders |
35 | { | ||
35 | /* Standard little endian byte order. | 36 | /* Standard little endian byte order. |
36 | EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */ | 37 | EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */ |
37 | floatformat_little, | 38 | floatformat_little, |
@@ -51,12 +52,13 @@ enum EXTRACTOR_floatformat_byteorders { | |||
51 | floatformat_vax | 52 | floatformat_vax |
52 | }; | 53 | }; |
53 | 54 | ||
54 | enum EXTRACTOR_floatformat_intbit { floatformat_intbit_yes, floatformat_intbit_no }; | 55 | enum EXTRACTOR_floatformat_intbit { floatformat_intbit_yes, |
56 | floatformat_intbit_no }; | ||
55 | 57 | ||
56 | struct EXTRACTOR_floatformat | 58 | struct EXTRACTOR_floatformat |
57 | { | 59 | { |
58 | enum EXTRACTOR_floatformat_byteorders byteorder; | 60 | enum EXTRACTOR_floatformat_byteorders byteorder; |
59 | unsigned int totalsize; /* Total size of number in bits */ | 61 | unsigned int totalsize; /* Total size of number in bits */ |
60 | 62 | ||
61 | /* Sign bit is always one bit long. 1 means negative, 0 means positive. */ | 63 | /* Sign bit is always one bit long. 1 means negative, 0 means positive. */ |
62 | unsigned int sign_start; | 64 | unsigned int sign_start; |
@@ -90,13 +92,16 @@ struct EXTRACTOR_floatformat | |||
90 | /* floatformats for IEEE single and double, big and little endian. */ | 92 | /* floatformats for IEEE single and double, big and little endian. */ |
91 | 93 | ||
92 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big; | 94 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big; |
93 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_little; | 95 | extern const struct EXTRACTOR_floatformat |
96 | EXTRACTOR_floatformat_ieee_single_little; | ||
94 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big; | 97 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big; |
95 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little; | 98 | extern const struct EXTRACTOR_floatformat |
99 | EXTRACTOR_floatformat_ieee_double_little; | ||
96 | 100 | ||
97 | /* floatformat for ARM IEEE double, little endian bytes and big endian words */ | 101 | /* floatformat for ARM IEEE double, little endian bytes and big endian words */ |
98 | 102 | ||
99 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_littlebyte_bigword; | 103 | extern const struct EXTRACTOR_floatformat |
104 | EXTRACTOR_floatformat_ieee_double_littlebyte_bigword; | ||
100 | 105 | ||
101 | /* floatformats for VAX. */ | 106 | /* floatformats for VAX. */ |
102 | 107 | ||
@@ -110,31 +115,38 @@ extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext; | |||
110 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext; | 115 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext; |
111 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext; | 116 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext; |
112 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext; | 117 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext; |
113 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext; | 118 | extern const struct EXTRACTOR_floatformat |
119 | EXTRACTOR_floatformat_m88110_harris_ext; | ||
114 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big; | 120 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big; |
115 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_littlebyte_bigword; | 121 | extern const struct EXTRACTOR_floatformat |
122 | EXTRACTOR_floatformat_arm_ext_littlebyte_bigword; | ||
116 | /* IA-64 Floating Point register spilt into memory. */ | 123 | /* IA-64 Floating Point register spilt into memory. */ |
117 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big; | 124 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big; |
118 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_little; | 125 | extern const struct EXTRACTOR_floatformat |
126 | EXTRACTOR_floatformat_ia64_spill_little; | ||
119 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big; | 127 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big; |
120 | extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little; | 128 | extern const struct EXTRACTOR_floatformat |
129 | EXTRACTOR_floatformat_ia64_quad_little; | ||
121 | 130 | ||
122 | /* Convert from FMT to a double. | 131 | /* Convert from FMT to a double. |
123 | FROM is the address of the extended float. | 132 | FROM is the address of the extended float. |
124 | Store the double in *TO. */ | 133 | Store the double in *TO. */ |
125 | 134 | ||
126 | extern void | 135 | extern void |
127 | EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *, const void *, double *); | 136 | EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *, |
137 | const void *, double *); | ||
128 | 138 | ||
129 | /* The converse: convert the double *FROM to FMT | 139 | /* The converse: convert the double *FROM to FMT |
130 | and store where TO points. */ | 140 | and store where TO points. */ |
131 | 141 | ||
132 | extern void | 142 | extern void |
133 | EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *, const double *, void *); | 143 | EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *, |
144 | const double *, void *); | ||
134 | 145 | ||
135 | /* Return non-zero iff the data at FROM is a valid number in format FMT. */ | 146 | /* Return non-zero iff the data at FROM is a valid number in format FMT. */ |
136 | 147 | ||
137 | extern int | 148 | extern int |
138 | EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt, const void *from); | 149 | EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt, |
150 | const void *from); | ||
139 | 151 | ||
140 | #endif /* defined (FLOATFORMAT_H) */ | 152 | #endif /* defined (FLOATFORMAT_H) */ |
diff --git a/src/plugins/old/ebml_extractor.c b/src/plugins/old/ebml_extractor.c index 2d52d90..f7daa9a 100644 --- a/src/plugins/old/ebml_extractor.c +++ b/src/plugins/old/ebml_extractor.c | |||
@@ -18,11 +18,11 @@ | |||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * Made by Gabriel Peixoto | 22 | * Made by Gabriel Peixoto |
23 | * Using AVInfo 1.x code. Copyright (c) 2004 George Shuklin. | 23 | * Using AVInfo 1.x code. Copyright (c) 2004 George Shuklin. |
24 | * Nearly complete rewrite by LRN, Copyright (c) 2012 | 24 | * Nearly complete rewrite by LRN, Copyright (c) 2012 |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "extractor.h" | 28 | #include "extractor.h" |
@@ -44,20 +44,25 @@ | |||
44 | struct tm * | 44 | struct tm * |
45 | gmtime_undocumented_64_r (const __time64_t *timer, struct tm *result) | 45 | gmtime_undocumented_64_r (const __time64_t *timer, struct tm *result) |
46 | { | 46 | { |
47 | struct tm *local_result = NULL;//_gmtime64 (timer); | 47 | struct tm *local_result = NULL; // _gmtime64 (timer); |
48 | 48 | ||
49 | if (local_result == NULL || result == NULL) | 49 | if ((local_result == NULL) || (result == NULL) ) |
50 | return NULL; | 50 | return NULL; |
51 | 51 | ||
52 | memcpy (result, local_result, sizeof (*result)); | 52 | memcpy (result, local_result, sizeof (*result)); |
53 | return result; | 53 | return result; |
54 | } | 54 | } |
55 | |||
56 | |||
55 | #endif | 57 | #endif |
56 | 58 | ||
57 | #include "extractor_plugins.h" | 59 | #include "extractor_plugins.h" |
58 | 60 | ||
59 | #define ADD_EBML(s,t) do { proc (proc_cls, "ebml", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1); } while (0) | 61 | #define ADD_EBML(s,t) do { proc (proc_cls, "ebml", t, EXTRACTOR_METAFORMAT_UTF8, \ |
60 | #define ADD_MATROSKA(s,t) do { proc (proc_cls, "matroska", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1); } while (0) | 62 | "text/plain", s, strlen (s) + 1); } while (0) |
63 | #define ADD_MATROSKA(s,t) do { proc (proc_cls, "matroska", t, \ | ||
64 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, \ | ||
65 | strlen (s) + 1); } while (0) | ||
61 | 66 | ||
62 | /** | 67 | /** |
63 | * String length limit. The spec does not limit the strings, | 68 | * String length limit. The spec does not limit the strings, |
@@ -162,9 +167,9 @@ struct MatroskaTagMap tag_map[] = { | |||
162 | {"KEYWORDS", EXTRACTOR_METATYPE_KEYWORDS}, | 167 | {"KEYWORDS", EXTRACTOR_METATYPE_KEYWORDS}, |
163 | {"SUMMARY", EXTRACTOR_METATYPE_SUMMARY}, | 168 | {"SUMMARY", EXTRACTOR_METATYPE_SUMMARY}, |
164 | /* | 169 | /* |
165 | SYNOPSIS UTF-8 A description of the story line of the item. | 170 | SYNOPSIS UTF-8 A description of the story line of the item. |
166 | INITIAL_KEY UTF-8 The initial key that a musical track starts in. The format is identical to ID3. | 171 | INITIAL_KEY UTF-8 The initial key that a musical track starts in. The format is identical to ID3. |
167 | PERIOD UTF-8 Describes the period that the piece is from or about. For example, "Renaissance". | 172 | PERIOD UTF-8 Describes the period that the piece is from or about. For example, "Renaissance". |
168 | LAW_RATING UTF-8 Depending on the country it's the format of the rating of a movie (P, R, X in the USA, an age in other countries or a URI defining a logo). | 173 | LAW_RATING UTF-8 Depending on the country it's the format of the rating of a movie (P, R, X in the USA, an age in other countries or a URI defining a logo). |
169 | ICRA binary The ICRA content rating for parental control. (Previously RSACi) | 174 | ICRA binary The ICRA content rating for parental control. (Previously RSACi) |
170 | */ | 175 | */ |
@@ -176,7 +181,7 @@ struct MatroskaTagMap tag_map[] = { | |||
176 | {"DATE_WRITTEN", EXTRACTOR_METATYPE_UNKNOWN_DATE}, | 181 | {"DATE_WRITTEN", EXTRACTOR_METATYPE_UNKNOWN_DATE}, |
177 | {"DATE_PURCHASED", EXTRACTOR_METATYPE_UNKNOWN_DATE}, | 182 | {"DATE_PURCHASED", EXTRACTOR_METATYPE_UNKNOWN_DATE}, |
178 | /* | 183 | /* |
179 | RECORDING_LOCATION UTF-8 The location where the item was recorded. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. This code is followed by a comma, then more detailed information such as state/province, another comma, and then city. For example, "US, Texas, Austin". This will allow for easy sorting. It is okay to only store the country, or the country and the state/province. More detailed information can be added after the city through the use of additional commas. In cases where the province/state is unknown, but you want to store the city, simply leave a space between the two commas. For example, "US, , Austin". | 184 | RECORDING_LOCATION UTF-8 The location where the item was recorded. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. This code is followed by a comma, then more detailed information such as state/province, another comma, and then city. For example, "US, Texas, Austin". This will allow for easy sorting. It is okay to only store the country, or the country and the state/province. More detailed information can be added after the city through the use of additional commas. In cases where the province/state is unknown, but you want to store the city, simply leave a space between the two commas. For example, "US, , Austin". |
180 | COMPOSITION_LOCATION UTF-8 Location that the item was originaly designed/written. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. This code is followed by a comma, then more detailed information such as state/province, another comma, and then city. For example, "US, Texas, Austin". This will allow for easy sorting. It is okay to only store the country, or the country and the state/province. More detailed information can be added after the city through the use of additional commas. In cases where the province/state is unknown, but you want to store the city, simply leave a space between the two commas. For example, "US, , Austin". | 185 | COMPOSITION_LOCATION UTF-8 Location that the item was originaly designed/written. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. This code is followed by a comma, then more detailed information such as state/province, another comma, and then city. For example, "US, Texas, Austin". This will allow for easy sorting. It is okay to only store the country, or the country and the state/province. More detailed information can be added after the city through the use of additional commas. In cases where the province/state is unknown, but you want to store the city, simply leave a space between the two commas. For example, "US, , Austin". |
181 | COMPOSER_NATIONALITY UTF-8 Nationality of the main composer of the item, mostly for classical music. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. | 186 | COMPOSER_NATIONALITY UTF-8 Nationality of the main composer of the item, mostly for classical music. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. |
182 | */ | 187 | */ |
@@ -188,7 +193,7 @@ struct MatroskaTagMap tag_map[] = { | |||
188 | ENCODER UTF-8 The software or hardware used to encode this item. ("LAME" or "XviD") | 193 | ENCODER UTF-8 The software or hardware used to encode this item. ("LAME" or "XviD") |
189 | ENCODER_SETTINGS UTF-8 A list of the settings used for encoding this item. No specific format. | 194 | ENCODER_SETTINGS UTF-8 A list of the settings used for encoding this item. No specific format. |
190 | BPS UTF-8 The average bits per second of the specified item. This is only the data in the Blocks, and excludes headers and any container overhead. | 195 | BPS UTF-8 The average bits per second of the specified item. This is only the data in the Blocks, and excludes headers and any container overhead. |
191 | FPS UTF-8 The average frames per second of the specified item. This is typically the average number of Blocks per second. In the event that lacing is used, each laced chunk is to be counted as a seperate frame. | 196 | FPS UTF-8 The average frames per second of the specified item. This is typically the average number of Blocks per second. In the event that lacing is used, each laced chunk is to be counted as a seperate frame. |
192 | */ | 197 | */ |
193 | {"BPM", EXTRACTOR_METATYPE_BEATS_PER_MINUTE}, | 198 | {"BPM", EXTRACTOR_METATYPE_BEATS_PER_MINUTE}, |
194 | /* | 199 | /* |
@@ -201,7 +206,7 @@ struct MatroskaTagMap tag_map[] = { | |||
201 | /* | 206 | /* |
202 | MCDI binary This is a binary dump of the TOC of the CDROM that this item was taken from. This holds the same information as the MCDI in ID3. | 207 | MCDI binary This is a binary dump of the TOC of the CDROM that this item was taken from. This holds the same information as the MCDI in ID3. |
203 | ISBN UTF-8 International Standard Book Number | 208 | ISBN UTF-8 International Standard Book Number |
204 | BARCODE UTF-8 EAN-13 (European Article Numbering) or UPC-A (Universal Product Code) bar code identifier | 209 | BARCODE UTF-8 EAN-13 (European Article Numbering) or UPC-A (Universal Product Code) bar code identifier |
205 | CATALOG_NUMBER UTF-8 A label-specific string used to identify the release (TIC 01 for example). | 210 | CATALOG_NUMBER UTF-8 A label-specific string used to identify the release (TIC 01 for example). |
206 | LABEL_CODE UTF-8 A 4-digit or 5-digit number to identify the record label, typically printed as (LC) xxxx or (LC) 0xxxx on CDs medias or covers (only the number is stored). | 211 | LABEL_CODE UTF-8 A 4-digit or 5-digit number to identify the record label, typically printed as (LC) xxxx or (LC) 0xxxx on CDs medias or covers (only the number is stored). |
207 | LCCN UTF-8 Library of Congress Control Number | 212 | LCCN UTF-8 Library of Congress Control Number |
@@ -281,7 +286,6 @@ enum | |||
281 | MatroskaID_Tracks_Audio_BitDepth = 0x6264, /* not 0, UINT. Bits per sample, mostly used for PCM. */ | 286 | MatroskaID_Tracks_Audio_BitDepth = 0x6264, /* not 0, UINT. Bits per sample, mostly used for PCM. */ |
282 | 287 | ||
283 | 288 | ||
284 | |||
285 | MatroskaID_Tags = 0x1254C367, /* can appear more than once. Element containing elements specific to Tracks/Chapters. A list of valid tags can be found here. */ | 289 | MatroskaID_Tags = 0x1254C367, /* can appear more than once. Element containing elements specific to Tracks/Chapters. A list of valid tags can be found here. */ |
286 | MatroskaID_Tags_Tag = 0x7373, /* mandatory, can appear more than once. Element containing elements specific to Tracks/Chapters. */ | 290 | MatroskaID_Tags_Tag = 0x7373, /* mandatory, can appear more than once. Element containing elements specific to Tracks/Chapters. */ |
287 | MatroskaID_Tags_Tag_SimpleTag = 0x67C8, /* mandatory, can appear more than once, recursive. Contains general information about the target. */ | 291 | MatroskaID_Tags_Tag_SimpleTag = 0x67C8, /* mandatory, can appear more than once, recursive. Contains general information about the target. */ |
@@ -315,12 +319,14 @@ enum VINTParseMode | |||
315 | */ | 319 | */ |
316 | static ssize_t | 320 | static ssize_t |
317 | VINTparse (struct EXTRACTOR_PluginList *plugin, | 321 | VINTparse (struct EXTRACTOR_PluginList *plugin, |
318 | int64_t * result, enum VINTParseMode mode) | 322 | int64_t *result, enum VINTParseMode mode) |
319 | { | 323 | { |
320 | /* 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001 */ | 324 | /* 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001 */ |
321 | static const unsigned char mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; | 325 | static const unsigned char mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, |
326 | 0x02, 0x01 }; | ||
322 | /* 01111111 00111111 00011111 00001111 00000111 00000011 00000001 00000000 */ | 327 | /* 01111111 00111111 00011111 00001111 00000111 00000011 00000001 00000000 */ |
323 | static const unsigned char imask[8] = { 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00 }; | 328 | static const unsigned char imask[8] = { 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, |
329 | 0x01, 0x00 }; | ||
324 | static const int64_t int_negative_limits[8] = { | 330 | static const int64_t int_negative_limits[8] = { |
325 | -0x00000000000040LL, /* 7-bit integer */ | 331 | -0x00000000000040LL, /* 7-bit integer */ |
326 | -0x00000000002000LL, /* 14-bit integer */ | 332 | -0x00000000002000LL, /* 14-bit integer */ |
@@ -374,13 +380,11 @@ VINTparse (struct EXTRACTOR_PluginList *plugin, | |||
374 | * 1-byte integer has 2^7 different values, | 380 | * 1-byte integer has 2^7 different values, |
375 | * 2-byte integer has 2^14 different values, | 381 | * 2-byte integer has 2^14 different values, |
376 | * etc | 382 | * etc |
377 | */ | 383 | *//* |
378 | /* | ||
379 | * Examine the first byte and see how many 0-bytes are at its beginning. | 384 | * Examine the first byte and see how many 0-bytes are at its beginning. |
380 | */ | 385 | */vint_width = 0; |
381 | vint_width = 0; | ||
382 | for (c = 0; c < 8; c++) | 386 | for (c = 0; c < 8; c++) |
383 | if (!(first_byte & mask[c])) | 387 | if (! (first_byte & mask[c])) |
384 | vint_width++; | 388 | vint_width++; |
385 | else | 389 | else |
386 | break; | 390 | break; |
@@ -403,7 +407,7 @@ VINTparse (struct EXTRACTOR_PluginList *plugin, | |||
403 | * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 407 | * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
404 | * 4-bit signed integer: | 408 | * 4-bit signed integer: |
405 | * 0 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1 | 409 | * 0 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1 |
406 | * | 410 | * |
407 | * 3 here is 0011b, and -3 is 1101b | 411 | * 3 here is 0011b, and -3 is 1101b |
408 | * However, writing 1101b into int8_t memory location will NOT make | 412 | * However, writing 1101b into int8_t memory location will NOT make |
409 | * the machine interpret it as -3, it will be interpreted as 00001101b, | 413 | * the machine interpret it as -3, it will be interpreted as 00001101b, |
@@ -427,9 +431,7 @@ VINTparse (struct EXTRACTOR_PluginList *plugin, | |||
427 | * which is outside of the signed integer range (remember, we're in 4-bit space here). | 431 | * which is outside of the signed integer range (remember, we're in 4-bit space here). |
428 | * on the other hand, 5 and -3 both are within the range. | 432 | * on the other hand, 5 and -3 both are within the range. |
429 | * 4) if the number does not exceed the signed integer maximum (7), store it as-is | 433 | * 4) if the number does not exceed the signed integer maximum (7), store it as-is |
430 | */ | 434 | */result_u = 0; |
431 | |||
432 | result_u = 0; | ||
433 | /* Copy the extra bytes into a temporary buffer, in the right order */ | 435 | /* Copy the extra bytes into a temporary buffer, in the right order */ |
434 | for (c = 0; c < vint_width; c++) | 436 | for (c = 0; c < vint_width; c++) |
435 | result_u += ((uint64_t) int_bytes[vint_width - c]) << (c * 8); | 437 | result_u += ((uint64_t) int_bytes[vint_width - c]) << (c * 8); |
@@ -439,7 +441,8 @@ VINTparse (struct EXTRACTOR_PluginList *plugin, | |||
439 | { | 441 | { |
440 | case VINT_READ_UINT: | 442 | case VINT_READ_UINT: |
441 | /* Unset the 1-bit marker */ | 443 | /* Unset the 1-bit marker */ |
442 | result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width * 8); | 444 | result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width |
445 | * 8); | ||
443 | memcpy (result, &result_u, sizeof (uint64_t)); | 446 | memcpy (result, &result_u, sizeof (uint64_t)); |
444 | break; | 447 | break; |
445 | case VINT_READ_ID: | 448 | case VINT_READ_ID: |
@@ -449,7 +452,8 @@ VINTparse (struct EXTRACTOR_PluginList *plugin, | |||
449 | break; | 452 | break; |
450 | case VINT_READ_SIZE: | 453 | case VINT_READ_SIZE: |
451 | /* Unset the 1-bit marker */ | 454 | /* Unset the 1-bit marker */ |
452 | result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width * 8); | 455 | result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width |
456 | * 8); | ||
453 | /* Special case: all-1 size means "size is unknown". We indicate this | 457 | /* Special case: all-1 size means "size is unknown". We indicate this |
454 | * in the return value by setting it to UINT64_MAX. | 458 | * in the return value by setting it to UINT64_MAX. |
455 | */ | 459 | */ |
@@ -459,7 +463,8 @@ VINTparse (struct EXTRACTOR_PluginList *plugin, | |||
459 | break; | 463 | break; |
460 | case VINT_READ_SINT: | 464 | case VINT_READ_SINT: |
461 | /* Unset the 1-bit marker */ | 465 | /* Unset the 1-bit marker */ |
462 | result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width * 8); | 466 | result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width |
467 | * 8); | ||
463 | /* Interpret large values as negative signed values */ | 468 | /* Interpret large values as negative signed values */ |
464 | if (result_u > int_positive_limits[vint_width]) | 469 | if (result_u > int_positive_limits[vint_width]) |
465 | { | 470 | { |
@@ -492,7 +497,7 @@ VINTparse (struct EXTRACTOR_PluginList *plugin, | |||
492 | */ | 497 | */ |
493 | static ssize_t | 498 | static ssize_t |
494 | elementRead (struct EXTRACTOR_PluginList *plugin, | 499 | elementRead (struct EXTRACTOR_PluginList *plugin, |
495 | uint32_t *id, int64_t * size) | 500 | uint32_t *id, int64_t *size) |
496 | { | 501 | { |
497 | int64_t tempID; | 502 | int64_t tempID; |
498 | int64_t tempsize; | 503 | int64_t tempsize; |
@@ -519,6 +524,7 @@ elementRead (struct EXTRACTOR_PluginList *plugin, | |||
519 | return id_offset + size_offset; | 524 | return id_offset + size_offset; |
520 | } | 525 | } |
521 | 526 | ||
527 | |||
522 | static ssize_t | 528 | static ssize_t |
523 | idRead (struct EXTRACTOR_PluginList *plugin, | 529 | idRead (struct EXTRACTOR_PluginList *plugin, |
524 | uint64_t length, uint32_t *id) | 530 | uint64_t length, uint32_t *id) |
@@ -537,8 +543,10 @@ idRead (struct EXTRACTOR_PluginList *plugin, | |||
537 | return id_offset; | 543 | return id_offset; |
538 | } | 544 | } |
539 | 545 | ||
546 | |||
540 | static ssize_t | 547 | static ssize_t |
541 | uintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, uint64_t *result) | 548 | uintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, |
549 | uint64_t *result) | ||
542 | { | 550 | { |
543 | size_t c; | 551 | size_t c; |
544 | unsigned char *data; | 552 | unsigned char *data; |
@@ -552,6 +560,7 @@ uintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, uint64_t *result | |||
552 | return (ssize_t) length; | 560 | return (ssize_t) length; |
553 | } | 561 | } |
554 | 562 | ||
563 | |||
555 | static ssize_t | 564 | static ssize_t |
556 | sintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, int64_t *result) | 565 | sintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, int64_t *result) |
557 | { | 566 | { |
@@ -579,6 +588,7 @@ sintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, int64_t *result) | |||
579 | return (ssize_t) length; | 588 | return (ssize_t) length; |
580 | } | 589 | } |
581 | 590 | ||
591 | |||
582 | static ssize_t | 592 | static ssize_t |
583 | stringRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, char *result) | 593 | stringRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, char *result) |
584 | { | 594 | { |
@@ -601,8 +611,10 @@ stringRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, char *result) | |||
601 | return 1; | 611 | return 1; |
602 | } | 612 | } |
603 | 613 | ||
614 | |||
604 | static ssize_t | 615 | static ssize_t |
605 | floatRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, long double *result) | 616 | floatRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, long |
617 | double *result) | ||
606 | { | 618 | { |
607 | size_t c; | 619 | size_t c; |
608 | unsigned char t[8]; | 620 | unsigned char t[8]; |
@@ -612,7 +624,7 @@ floatRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, long double *re | |||
612 | return -1; | 624 | return -1; |
613 | 625 | ||
614 | /* we don't support 10-byte floats, because not all C compilers will guarantee that long double is stored in 10 bytes in a IEEE-conformant format */ | 626 | /* we don't support 10-byte floats, because not all C compilers will guarantee that long double is stored in 10 bytes in a IEEE-conformant format */ |
615 | if (length != 4 && length != 8 /* && length != 10 */) | 627 | if ((length != 4) && (length != 8) /* && length != 10 */) |
616 | return 0; | 628 | return 0; |
617 | 629 | ||
618 | for (c = 0; c < length; c++) | 630 | for (c = 0; c < length; c++) |
@@ -624,14 +636,15 @@ floatRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, long double *re | |||
624 | #endif | 636 | #endif |
625 | } | 637 | } |
626 | if (length == 4) | 638 | if (length == 4) |
627 | *result = * ((float *) t); | 639 | *result = *((float *) t); |
628 | else if (length == 8) | 640 | else if (length == 8) |
629 | *result = * ((double *) t); | 641 | *result = *((double *) t); |
630 | else | 642 | else |
631 | *result = * ((long double *) t); | 643 | *result = *((long double *) t); |
632 | return (ssize_t) length; | 644 | return (ssize_t) length; |
633 | } | 645 | } |
634 | 646 | ||
647 | |||
635 | static const char stream_type_letters[] = "?vat"; /*[0]-no, [1]-video,[2]-audio,[3]-text */ | 648 | static const char stream_type_letters[] = "?vat"; /*[0]-no, [1]-video,[2]-audio,[3]-text */ |
636 | 649 | ||
637 | enum EBMLState | 650 | enum EBMLState |
@@ -791,6 +804,7 @@ clean_ebml_state_ebml (struct ebml_state *state) | |||
791 | state->doctype_read_version = 0; | 804 | state->doctype_read_version = 0; |
792 | } | 805 | } |
793 | 806 | ||
807 | |||
794 | static void | 808 | static void |
795 | clean_ebml_state_matroska_simpletags (struct ebml_state *state) | 809 | clean_ebml_state_matroska_simpletags (struct ebml_state *state) |
796 | { | 810 | { |
@@ -809,7 +823,7 @@ clean_ebml_state_matroska_simpletags (struct ebml_state *state) | |||
809 | if (el->string != NULL) | 823 | if (el->string != NULL) |
810 | free (el->string); | 824 | free (el->string); |
811 | free (el); | 825 | free (el); |
812 | if (parent != NULL && parent->child == el) | 826 | if ((parent != NULL) && (parent->child == el)) |
813 | parent->child = next; | 827 | parent->child = next; |
814 | el = next; | 828 | el = next; |
815 | if (next == NULL) | 829 | if (next == NULL) |
@@ -820,8 +834,10 @@ clean_ebml_state_matroska_simpletags (struct ebml_state *state) | |||
820 | state->tag_current = NULL; | 834 | state->tag_current = NULL; |
821 | } | 835 | } |
822 | 836 | ||
837 | |||
823 | void | 838 | void |
824 | matroska_add_tag (struct ebml_state *state, struct matroska_simpletag *parent, char *name, char *string) | 839 | matroska_add_tag (struct ebml_state *state, struct matroska_simpletag *parent, |
840 | char *name, char *string) | ||
825 | { | 841 | { |
826 | struct matroska_simpletag *el = malloc (sizeof (struct matroska_simpletag)); | 842 | struct matroska_simpletag *el = malloc (sizeof (struct matroska_simpletag)); |
827 | el->parent = parent; | 843 | el->parent = parent; |
@@ -839,6 +855,7 @@ matroska_add_tag (struct ebml_state *state, struct matroska_simpletag *parent, c | |||
839 | state->tag_last = el; | 855 | state->tag_last = el; |
840 | } | 856 | } |
841 | 857 | ||
858 | |||
842 | static void | 859 | static void |
843 | clean_ebml_state_matroska_seeks (struct ebml_state *state) | 860 | clean_ebml_state_matroska_seeks (struct ebml_state *state) |
844 | { | 861 | { |
@@ -852,6 +869,7 @@ clean_ebml_state_matroska_seeks (struct ebml_state *state) | |||
852 | state->matroska_seeks_tail = NULL; | 869 | state->matroska_seeks_tail = NULL; |
853 | } | 870 | } |
854 | 871 | ||
872 | |||
855 | static void | 873 | static void |
856 | clean_ebml_state_matroska_segment (struct ebml_state *state) | 874 | clean_ebml_state_matroska_segment (struct ebml_state *state) |
857 | { | 875 | { |
@@ -862,6 +880,7 @@ clean_ebml_state_matroska_segment (struct ebml_state *state) | |||
862 | clean_ebml_state_matroska_simpletags (state); | 880 | clean_ebml_state_matroska_simpletags (state); |
863 | } | 881 | } |
864 | 882 | ||
883 | |||
865 | static void | 884 | static void |
866 | clean_ebml_state_matroska_seek (struct ebml_state *state) | 885 | clean_ebml_state_matroska_seek (struct ebml_state *state) |
867 | { | 886 | { |
@@ -869,6 +888,7 @@ clean_ebml_state_matroska_seek (struct ebml_state *state) | |||
869 | state->matroska_seek_position = 0; | 888 | state->matroska_seek_position = 0; |
870 | } | 889 | } |
871 | 890 | ||
891 | |||
872 | static void | 892 | static void |
873 | clean_ebml_state_matroska_info (struct ebml_state *state) | 893 | clean_ebml_state_matroska_info (struct ebml_state *state) |
874 | { | 894 | { |
@@ -889,6 +909,7 @@ clean_ebml_state_matroska_info (struct ebml_state *state) | |||
889 | state->matroska_info_writing_app = NULL; | 909 | state->matroska_info_writing_app = NULL; |
890 | } | 910 | } |
891 | 911 | ||
912 | |||
892 | static void | 913 | static void |
893 | clean_ebml_state_matroska_track_video (struct ebml_state *state) | 914 | clean_ebml_state_matroska_track_video (struct ebml_state *state) |
894 | { | 915 | { |
@@ -902,6 +923,7 @@ clean_ebml_state_matroska_track_video (struct ebml_state *state) | |||
902 | state->matroska_track_video_display_unit = 0; | 923 | state->matroska_track_video_display_unit = 0; |
903 | } | 924 | } |
904 | 925 | ||
926 | |||
905 | static void | 927 | static void |
906 | clean_ebml_state_matroska_track_audio (struct ebml_state *state) | 928 | clean_ebml_state_matroska_track_audio (struct ebml_state *state) |
907 | { | 929 | { |
@@ -912,6 +934,7 @@ clean_ebml_state_matroska_track_audio (struct ebml_state *state) | |||
912 | state->matroska_track_audio_bit_depth = 0; | 934 | state->matroska_track_audio_bit_depth = 0; |
913 | } | 935 | } |
914 | 936 | ||
937 | |||
915 | static void | 938 | static void |
916 | clean_ebml_state_matroska_track (struct ebml_state *state) | 939 | clean_ebml_state_matroska_track (struct ebml_state *state) |
917 | { | 940 | { |
@@ -935,6 +958,7 @@ clean_ebml_state_matroska_track (struct ebml_state *state) | |||
935 | clean_ebml_state_matroska_track_audio (state); | 958 | clean_ebml_state_matroska_track_audio (state); |
936 | } | 959 | } |
937 | 960 | ||
961 | |||
938 | static struct ebml_state * | 962 | static struct ebml_state * |
939 | EXTRACTOR_ebml_init_state_method () | 963 | EXTRACTOR_ebml_init_state_method () |
940 | { | 964 | { |
@@ -952,14 +976,17 @@ EXTRACTOR_ebml_init_state_method () | |||
952 | return state; | 976 | return state; |
953 | } | 977 | } |
954 | 978 | ||
979 | |||
955 | static void | 980 | static void |
956 | report_simpletag (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *proc_cls) | 981 | report_simpletag (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, |
982 | void *proc_cls) | ||
957 | { | 983 | { |
958 | struct matroska_simpletag *el, *next; | 984 | struct matroska_simpletag *el, *next; |
959 | char format[MAX_STRING_SIZE + 1]; | 985 | char format[MAX_STRING_SIZE + 1]; |
960 | for (el = state->tag_tree; el != NULL; el = next) | 986 | for (el = state->tag_tree; el != NULL; el = next) |
961 | { | 987 | { |
962 | if (el->name != NULL && el->name[0] != '\0' && el->string != NULL && el->string[0] != '\0') | 988 | if ((el->name != NULL) && (el->name[0] != '\0') && (el->string != NULL) && |
989 | (el->string[0] != '\0') ) | ||
963 | { | 990 | { |
964 | enum EXTRACTOR_MetaType metatype = EXTRACTOR_METATYPE_RESERVED; | 991 | enum EXTRACTOR_MetaType metatype = EXTRACTOR_METATYPE_RESERVED; |
965 | struct MatroskaTagMap *map_item; | 992 | struct MatroskaTagMap *map_item; |
@@ -975,10 +1002,10 @@ report_simpletag (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, vo | |||
975 | { | 1002 | { |
976 | snprintf (format, MAX_STRING_SIZE, "%s=%s", el->name, el->string); | 1003 | snprintf (format, MAX_STRING_SIZE, "%s=%s", el->name, el->string); |
977 | format[MAX_STRING_SIZE] = '\0'; | 1004 | format[MAX_STRING_SIZE] = '\0'; |
978 | ADD_MATROSKA(format, EXTRACTOR_METATYPE_UNKNOWN); | 1005 | ADD_MATROSKA (format, EXTRACTOR_METATYPE_UNKNOWN); |
979 | } | 1006 | } |
980 | else | 1007 | else |
981 | ADD_MATROSKA(el->string, metatype); | 1008 | ADD_MATROSKA (el->string, metatype); |
982 | } | 1009 | } |
983 | next = el->child; | 1010 | next = el->child; |
984 | while (next == NULL && el != NULL) | 1011 | while (next == NULL && el != NULL) |
@@ -991,18 +1018,21 @@ report_simpletag (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, vo | |||
991 | clean_ebml_state_matroska_simpletags (state); | 1018 | clean_ebml_state_matroska_simpletags (state); |
992 | } | 1019 | } |
993 | 1020 | ||
1021 | |||
994 | static void | 1022 | static void |
995 | report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *proc_cls) | 1023 | report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, |
1024 | void *proc_cls) | ||
996 | { | 1025 | { |
997 | char format[MAX_STRING_SIZE + 1]; | 1026 | char format[MAX_STRING_SIZE + 1]; |
998 | report_simpletag (state, proc, proc_cls); | 1027 | report_simpletag (state, proc, proc_cls); |
999 | if (state->valid_ebml && !state->reported_ebml) | 1028 | if (state->valid_ebml && ! state->reported_ebml) |
1000 | { | 1029 | { |
1001 | state->reported_ebml = 1; | 1030 | state->reported_ebml = 1; |
1002 | snprintf (format, MAX_STRING_SIZE, "%llu", (unsigned long long) state->ebml_version); | 1031 | snprintf (format, MAX_STRING_SIZE, "%llu", (unsigned long |
1032 | long) state->ebml_version); | ||
1003 | format[MAX_STRING_SIZE] = '\0'; | 1033 | format[MAX_STRING_SIZE] = '\0'; |
1004 | ADD_EBML(format, EXTRACTOR_METATYPE_FORMAT_VERSION); | 1034 | ADD_EBML (format, EXTRACTOR_METATYPE_FORMAT_VERSION); |
1005 | snprintf (format, MAX_STRING_SIZE, "%s %llu (EBML %llu)", state->doctype, | 1035 | snprintf (format, MAX_STRING_SIZE, "%s %llu (EBML %llu)", state->doctype, |
1006 | (unsigned long long) state->doctype_version, | 1036 | (unsigned long long) state->doctype_version, |
1007 | (unsigned long long) state->ebml_version); | 1037 | (unsigned long long) state->ebml_version); |
1008 | format[MAX_STRING_SIZE] = '\0'; | 1038 | format[MAX_STRING_SIZE] = '\0'; |
@@ -1012,21 +1042,25 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void * | |||
1012 | clean_ebml_state_ebml (state); | 1042 | clean_ebml_state_ebml (state); |
1013 | if (state->valid_matroska_info == -1) | 1043 | if (state->valid_matroska_info == -1) |
1014 | { | 1044 | { |
1015 | if ((state->matroska_info_duration > 0 || state->matroska_info_duration == -1.0) && | 1045 | if (((state->matroska_info_duration > 0) || |
1016 | state->matroska_info_muxing_app != NULL && state->matroska_info_writing_app != NULL) | 1046 | (state->matroska_info_duration == -1.0) ) && |
1047 | (state->matroska_info_muxing_app != NULL) && | ||
1048 | (state->matroska_info_writing_app != NULL) ) | ||
1017 | state->valid_matroska_info = 1; | 1049 | state->valid_matroska_info = 1; |
1018 | else | 1050 | else |
1019 | state->valid_matroska_info = 0; | 1051 | state->valid_matroska_info = 0; |
1020 | } | 1052 | } |
1021 | if (state->valid_matroska_info == 1 && !state->reported_matroska_info) | 1053 | if ((state->valid_matroska_info == 1) && ! state->reported_matroska_info) |
1022 | { | 1054 | { |
1023 | state->reported_matroska_info = 1; | 1055 | state->reported_matroska_info = 1; |
1024 | if (state->matroska_info_duration != -1.0) | 1056 | if (state->matroska_info_duration != -1.0) |
1025 | { | 1057 | { |
1026 | uint64_t seconds = (uint64_t) ((state->matroska_info_duration * (float) state->matroska_info_timecode_scale) / 1e+9); | 1058 | uint64_t seconds = (uint64_t) ((state->matroska_info_duration |
1059 | * (float) state-> | ||
1060 | matroska_info_timecode_scale) / 1e+9); | ||
1027 | snprintf (format, MAX_STRING_SIZE, "%llus", (unsigned long long) seconds); | 1061 | snprintf (format, MAX_STRING_SIZE, "%llus", (unsigned long long) seconds); |
1028 | format[MAX_STRING_SIZE] = '\0'; | 1062 | format[MAX_STRING_SIZE] = '\0'; |
1029 | ADD_MATROSKA(format, EXTRACTOR_METATYPE_DURATION); | 1063 | ADD_MATROSKA (format, EXTRACTOR_METATYPE_DURATION); |
1030 | } | 1064 | } |
1031 | if (state->matroska_info_date_utc_is_set) | 1065 | if (state->matroska_info_date_utc_is_set) |
1032 | { | 1066 | { |
@@ -1052,8 +1086,7 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void * | |||
1052 | * millenium is known and never changes), but we want to use 64-bit integer to | 1086 | * millenium is known and never changes), but we want to use 64-bit integer to |
1053 | * manipulate time. If it gets trimmed later, when assigning back to a TIME_TYPE | 1087 | * manipulate time. If it gets trimmed later, when assigning back to a TIME_TYPE |
1054 | * that happens to be 32-bit long - well, tough luck. | 1088 | * that happens to be 32-bit long - well, tough luck. |
1055 | */ | 1089 | */errno = 0; |
1056 | errno = 0; | ||
1057 | #if WINDOWS | 1090 | #if WINDOWS |
1058 | millenium_start_stamp = _mktime64 (&millenium_start); | 1091 | millenium_start_stamp = _mktime64 (&millenium_start); |
1059 | #else | 1092 | #else |
@@ -1061,58 +1094,69 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void * | |||
1061 | #endif | 1094 | #endif |
1062 | if (millenium_start_stamp == -1) | 1095 | if (millenium_start_stamp == -1) |
1063 | printf ("Failed to convert time: %d\n", errno); | 1096 | printf ("Failed to convert time: %d\n", errno); |
1064 | matroska_date_stamp = millenium_start_stamp * 1000000000 + state->matroska_info_date_utc; | 1097 | matroska_date_stamp = millenium_start_stamp * 1000000000 |
1098 | + state->matroska_info_date_utc; | ||
1065 | /* Now matroska_date_stamp is the number of nanoseconds since UNIX Epoch */ | 1099 | /* Now matroska_date_stamp is the number of nanoseconds since UNIX Epoch */ |
1066 | matroska_date_stamp_time_t = matroska_date_stamp / 1000000000; | 1100 | matroska_date_stamp_time_t = matroska_date_stamp / 1000000000; |
1067 | /* Now matroska_date_stamp_time_t is the number of seconds since UNIX Epoch */ | 1101 | /* Now matroska_date_stamp_time_t is the number of seconds since UNIX Epoch */ |
1068 | #if WINDOWS | 1102 | #if WINDOWS |
1069 | if (NULL != gmtime_undocumented_64_r (&matroska_date_stamp_time_t, &matroska_date)) | 1103 | if (NULL != gmtime_undocumented_64_r (&matroska_date_stamp_time_t, |
1104 | &matroska_date)) | ||
1070 | #else | 1105 | #else |
1071 | /* We want to be thread-safe. If you have no gmtime_r(), think of something! */ | 1106 | /* We want to be thread-safe. If you have no gmtime_r(), think of something! */ |
1072 | if (NULL != gmtime_r (&matroska_date_stamp_time_t, &matroska_date)) | 1107 | if (NULL != gmtime_r (&matroska_date_stamp_time_t, &matroska_date)) |
1073 | #endif | 1108 | #endif |
1074 | { | 1109 | { |
1075 | if (0 != strftime (format, MAX_STRING_SIZE, "%Y.%m.%d %H:%M:%S UTC", &matroska_date)) | 1110 | if (0 != strftime (format, MAX_STRING_SIZE, "%Y.%m.%d %H:%M:%S UTC", |
1076 | ADD_MATROSKA(format, EXTRACTOR_METATYPE_CREATION_DATE); | 1111 | &matroska_date)) |
1112 | ADD_MATROSKA (format, EXTRACTOR_METATYPE_CREATION_DATE); | ||
1077 | } | 1113 | } |
1078 | } | 1114 | } |
1079 | if (state->matroska_info_title != NULL) | 1115 | if (state->matroska_info_title != NULL) |
1080 | ADD_MATROSKA(state->matroska_info_title, EXTRACTOR_METATYPE_TITLE); | 1116 | ADD_MATROSKA (state->matroska_info_title, EXTRACTOR_METATYPE_TITLE); |
1081 | if (strcmp (state->matroska_info_writing_app, state->matroska_info_muxing_app) == 0) | 1117 | if (strcmp (state->matroska_info_writing_app, |
1082 | snprintf (format, MAX_STRING_SIZE, "Written and muxed with %s", state->matroska_info_writing_app); | 1118 | state->matroska_info_muxing_app) == 0) |
1119 | snprintf (format, MAX_STRING_SIZE, "Written and muxed with %s", | ||
1120 | state->matroska_info_writing_app); | ||
1083 | else | 1121 | else |
1084 | snprintf (format, MAX_STRING_SIZE, "Written with %s, muxed with %s", state->matroska_info_writing_app, state->matroska_info_muxing_app); | 1122 | snprintf (format, MAX_STRING_SIZE, "Written with %s, muxed with %s", |
1123 | state->matroska_info_writing_app, | ||
1124 | state->matroska_info_muxing_app); | ||
1085 | format[MAX_STRING_SIZE] = '\0'; | 1125 | format[MAX_STRING_SIZE] = '\0'; |
1086 | ADD_MATROSKA(format, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); | 1126 | ADD_MATROSKA (format, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); |
1087 | } | 1127 | } |
1088 | if (state->valid_matroska_info == 1) | 1128 | if (state->valid_matroska_info == 1) |
1089 | clean_ebml_state_matroska_info (state); | 1129 | clean_ebml_state_matroska_info (state); |
1090 | if (state->valid_matroska_track == -1) | 1130 | if (state->valid_matroska_track == -1) |
1091 | { | 1131 | { |
1092 | if ((state->matroska_track_type > 0 && state->matroska_track_type < 255) && | 1132 | if (((state->matroska_track_type > 0) && (state->matroska_track_type < |
1093 | state->matroska_track_codec_id != NULL) | 1133 | 255) ) && |
1134 | (state->matroska_track_codec_id != NULL) ) | ||
1094 | state->valid_matroska_track = 1; | 1135 | state->valid_matroska_track = 1; |
1095 | else | 1136 | else |
1096 | state->valid_matroska_track = 0; | 1137 | state->valid_matroska_track = 0; |
1097 | } | 1138 | } |
1098 | if (state->valid_matroska_track_video == -1) | 1139 | if (state->valid_matroska_track_video == -1) |
1099 | { | 1140 | { |
1100 | if ((state->matroska_track_video_flag_interlaced == 0 || state->matroska_track_video_flag_interlaced == 1) && | 1141 | if (((state->matroska_track_video_flag_interlaced == 0) || |
1101 | (state->matroska_track_video_stereo_mode >= 0 && state->matroska_track_video_stereo_mode <= 14) && | 1142 | (state->matroska_track_video_flag_interlaced == 1) ) && |
1102 | state->matroska_track_video_pixel_width > 0 && state->matroska_track_video_pixel_height > 0) | 1143 | ((state->matroska_track_video_stereo_mode >= 0) && |
1144 | (state->matroska_track_video_stereo_mode <= 14) ) && | ||
1145 | (state->matroska_track_video_pixel_width > 0) && | ||
1146 | (state->matroska_track_video_pixel_height > 0) ) | ||
1103 | state->valid_matroska_track_video = 1; | 1147 | state->valid_matroska_track_video = 1; |
1104 | else | 1148 | else |
1105 | state->valid_matroska_track_video = 0; | 1149 | state->valid_matroska_track_video = 0; |
1106 | } | 1150 | } |
1107 | if (state->valid_matroska_track_audio == -1) | 1151 | if (state->valid_matroska_track_audio == -1) |
1108 | { | 1152 | { |
1109 | if (state->matroska_track_audio_sampling_frequency > 0 && | 1153 | if ((state->matroska_track_audio_sampling_frequency > 0) && |
1110 | state->matroska_track_audio_channels > 0) | 1154 | (state->matroska_track_audio_channels > 0) ) |
1111 | state->valid_matroska_track_audio = 1; | 1155 | state->valid_matroska_track_audio = 1; |
1112 | else | 1156 | else |
1113 | state->valid_matroska_track_audio = 0; | 1157 | state->valid_matroska_track_audio = 0; |
1114 | } | 1158 | } |
1115 | if (state->valid_matroska_track == 1 && !state->reported_matroska_track) | 1159 | if ((state->valid_matroska_track == 1) && ! state->reported_matroska_track) |
1116 | { | 1160 | { |
1117 | char name_part[MAX_STRING_SIZE + 1]; | 1161 | char name_part[MAX_STRING_SIZE + 1]; |
1118 | char codec_part[MAX_STRING_SIZE + 1]; | 1162 | char codec_part[MAX_STRING_SIZE + 1]; |
@@ -1142,28 +1186,32 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void * | |||
1142 | if (state->matroska_track_name == NULL) | 1186 | if (state->matroska_track_name == NULL) |
1143 | snprintf (name_part, MAX_STRING_SIZE, "%s", ""); | 1187 | snprintf (name_part, MAX_STRING_SIZE, "%s", ""); |
1144 | else | 1188 | else |
1145 | snprintf (name_part, MAX_STRING_SIZE, "`%s' ", state->matroska_track_name); | 1189 | snprintf (name_part, MAX_STRING_SIZE, "`%s' ", |
1190 | state->matroska_track_name); | ||
1146 | name_part[MAX_STRING_SIZE] = '\0'; | 1191 | name_part[MAX_STRING_SIZE] = '\0'; |
1147 | 1192 | ||
1148 | if (state->matroska_track_codec_name == NULL) | 1193 | if (state->matroska_track_codec_name == NULL) |
1149 | snprintf (codec_part, MAX_STRING_SIZE, "%s", state->matroska_track_codec_id); | 1194 | snprintf (codec_part, MAX_STRING_SIZE, "%s", |
1195 | state->matroska_track_codec_id); | ||
1150 | else | 1196 | else |
1151 | snprintf (codec_part, MAX_STRING_SIZE, "%s [%s]", state->matroska_track_codec_id, state->matroska_track_codec_name); | 1197 | snprintf (codec_part, MAX_STRING_SIZE, "%s [%s]", |
1198 | state->matroska_track_codec_id, | ||
1199 | state->matroska_track_codec_name); | ||
1152 | codec_part[MAX_STRING_SIZE] = '\0'; | 1200 | codec_part[MAX_STRING_SIZE] = '\0'; |
1153 | 1201 | ||
1154 | if (use_video && state->valid_matroska_track_video == 1) | 1202 | if (use_video && (state->valid_matroska_track_video == 1)) |
1155 | { | 1203 | { |
1156 | /* Ignore Display* for now. Aspect ratio correction could be | 1204 | /* Ignore Display* for now. Aspect ratio correction could be |
1157 | * done either way (stretching horizontally or squishing vertically), | 1205 | * done either way (stretching horizontally or squishing vertically), |
1158 | * so let's stick to hard cold pixel counts. | 1206 | * so let's stick to hard cold pixel counts. |
1159 | */ | 1207 | */ |
1160 | snprintf (format, MAX_STRING_SIZE, "%llux%llu", | 1208 | snprintf (format, MAX_STRING_SIZE, "%llux%llu", |
1161 | (unsigned long long) state->matroska_track_video_pixel_width, | 1209 | (unsigned long long) state->matroska_track_video_pixel_width, |
1162 | (unsigned long long) state->matroska_track_video_pixel_height); | 1210 | (unsigned long long) state->matroska_track_video_pixel_height); |
1163 | format[MAX_STRING_SIZE] = '\0'; | 1211 | format[MAX_STRING_SIZE] = '\0'; |
1164 | ADD_MATROSKA (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); | 1212 | ADD_MATROSKA (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); |
1165 | } | 1213 | } |
1166 | if (use_audio && state->valid_matroska_track_audio == 1) | 1214 | if (use_audio && (state->valid_matroska_track_audio == 1)) |
1167 | { | 1215 | { |
1168 | double freq = state->matroska_track_audio_sampling_frequency; | 1216 | double freq = state->matroska_track_audio_sampling_frequency; |
1169 | double rfreq = freq; | 1217 | double rfreq = freq; |
@@ -1176,20 +1224,24 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void * | |||
1176 | hz_part[MAX_STRING_SIZE] = '\0'; | 1224 | hz_part[MAX_STRING_SIZE] = '\0'; |
1177 | 1225 | ||
1178 | if (state->matroska_track_audio_bit_depth > 0) | 1226 | if (state->matroska_track_audio_bit_depth > 0) |
1179 | snprintf (bit_part, MAX_STRING_SIZE, "%llu-bit ", (unsigned long long) state->matroska_track_audio_bit_depth); | 1227 | snprintf (bit_part, MAX_STRING_SIZE, "%llu-bit ", (unsigned long |
1228 | long) state-> | ||
1229 | matroska_track_audio_bit_depth); | ||
1180 | else | 1230 | else |
1181 | bit_part[0] = '\0'; | 1231 | bit_part[0] = '\0'; |
1182 | bit_part[MAX_STRING_SIZE] = '\0'; | 1232 | bit_part[MAX_STRING_SIZE] = '\0'; |
1183 | 1233 | ||
1184 | snprintf (format, MAX_STRING_SIZE, "%s track %s(%s, %llu-channel %sat %s) [%s]", | 1234 | snprintf (format, MAX_STRING_SIZE, |
1185 | track_type_string, name_part, codec_part, | 1235 | "%s track %s(%s, %llu-channel %sat %s) [%s]", |
1186 | (unsigned long long) state->matroska_track_audio_channels, | 1236 | track_type_string, name_part, codec_part, |
1187 | bit_part, hz_part, state->matroska_track_language); | 1237 | (unsigned long long) state->matroska_track_audio_channels, |
1238 | bit_part, hz_part, state->matroska_track_language); | ||
1188 | } | 1239 | } |
1189 | else | 1240 | else |
1190 | { | 1241 | { |
1191 | snprintf (format, MAX_STRING_SIZE, "%s track %s(%s) [%s]", | 1242 | snprintf (format, MAX_STRING_SIZE, "%s track %s(%s) [%s]", |
1192 | track_type_string, name_part, codec_part, state->matroska_track_language); | 1243 | track_type_string, name_part, codec_part, |
1244 | state->matroska_track_language); | ||
1193 | } | 1245 | } |
1194 | format[MAX_STRING_SIZE] = '\0'; | 1246 | format[MAX_STRING_SIZE] = '\0'; |
1195 | ADD_EBML (format, EXTRACTOR_METATYPE_RESOURCE_TYPE); | 1247 | ADD_EBML (format, EXTRACTOR_METATYPE_RESOURCE_TYPE); |
@@ -1199,7 +1251,7 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void * | |||
1199 | } | 1251 | } |
1200 | 1252 | ||
1201 | 1253 | ||
1202 | static int | 1254 | static int |
1203 | EXTRACTOR_ebml_discard_state_method (struct ebml_state *state) | 1255 | EXTRACTOR_ebml_discard_state_method (struct ebml_state *state) |
1204 | { | 1256 | { |
1205 | if (state != NULL) | 1257 | if (state != NULL) |
@@ -1214,6 +1266,7 @@ EXTRACTOR_ebml_discard_state_method (struct ebml_state *state) | |||
1214 | return 1; | 1266 | return 1; |
1215 | } | 1267 | } |
1216 | 1268 | ||
1269 | |||
1217 | static struct ebml_element * | 1270 | static struct ebml_element * |
1218 | ebml_stack_pop (struct ebml_state *state) | 1271 | ebml_stack_pop (struct ebml_state *state) |
1219 | { | 1272 | { |
@@ -1227,7 +1280,10 @@ ebml_stack_pop (struct ebml_state *state) | |||
1227 | 1280 | ||
1228 | 1281 | ||
1229 | static void | 1282 | static void |
1230 | ebml_stack_push_new (struct ebml_state *state, uint64_t position, uint32_t id, uint64_t size, uint64_t header_size, int finish_state, int prev_state, int bail_state, int bail_next_state) | 1283 | ebml_stack_push_new (struct ebml_state *state, uint64_t position, uint32_t id, |
1284 | uint64_t size, uint64_t header_size, int finish_state, int | ||
1285 | prev_state, int | ||
1286 | bail_state, int bail_next_state) | ||
1231 | { | 1287 | { |
1232 | struct ebml_element *element = malloc (sizeof (struct ebml_element)); | 1288 | struct ebml_element *element = malloc (sizeof (struct ebml_element)); |
1233 | element->parent = state->stack_top; | 1289 | element->parent = state->stack_top; |
@@ -1242,8 +1298,10 @@ ebml_stack_push_new (struct ebml_state *state, uint64_t position, uint32_t id, u | |||
1242 | element->bail_next_state = bail_next_state; | 1298 | element->bail_next_state = bail_next_state; |
1243 | } | 1299 | } |
1244 | 1300 | ||
1301 | |||
1245 | static int | 1302 | static int |
1246 | check_result (struct EXTRACTOR_PluginList *plugin, ssize_t read_result, struct ebml_state *state) | 1303 | check_result (struct EXTRACTOR_PluginList *plugin, ssize_t read_result, struct |
1304 | ebml_state *state) | ||
1247 | { | 1305 | { |
1248 | if (read_result == 0) | 1306 | if (read_result == 0) |
1249 | { | 1307 | { |
@@ -1256,7 +1314,7 @@ check_result (struct EXTRACTOR_PluginList *plugin, ssize_t read_result, struct e | |||
1256 | return 0; | 1314 | return 0; |
1257 | } | 1315 | } |
1258 | offset = parent->position + parent->header_size + parent->size; | 1316 | offset = parent->position + parent->header_size + parent->size; |
1259 | if (offset < 0 || offset != pl_seek (plugin, offset, SEEK_SET)) | 1317 | if ((offset < 0) || (offset != pl_seek (plugin, offset, SEEK_SET))) |
1260 | { | 1318 | { |
1261 | state->state = EBML_BAD_STATE; | 1319 | state->state = EBML_BAD_STATE; |
1262 | return 0; | 1320 | return 0; |
@@ -1269,12 +1327,16 @@ check_result (struct EXTRACTOR_PluginList *plugin, ssize_t read_result, struct e | |||
1269 | return 1; | 1327 | return 1; |
1270 | } | 1328 | } |
1271 | 1329 | ||
1330 | |||
1272 | static int | 1331 | static int |
1273 | maybe_rise_up (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state, int *do_break, int64_t read_result) | 1332 | maybe_rise_up (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state, |
1333 | int *do_break, int64_t read_result) | ||
1274 | { | 1334 | { |
1275 | int64_t offset; | 1335 | int64_t offset; |
1276 | offset = pl_get_pos (plugin) - read_result; | 1336 | offset = pl_get_pos (plugin) - read_result; |
1277 | if (state->stack_top != NULL && offset >= state->stack_top->position + state->stack_top->header_size + state->stack_top->size) | 1337 | if ((state->stack_top != NULL) && (offset >= state->stack_top->position |
1338 | + state->stack_top->header_size | ||
1339 | + state->stack_top->size) ) | ||
1278 | { | 1340 | { |
1279 | state->state = state->stack_top->finish_state; | 1341 | state->state = state->stack_top->finish_state; |
1280 | pl_seek (plugin, -read_result, SEEK_CUR); | 1342 | pl_seek (plugin, -read_result, SEEK_CUR); |
@@ -1284,24 +1346,29 @@ maybe_rise_up (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state, in | |||
1284 | return 0; | 1346 | return 0; |
1285 | } | 1347 | } |
1286 | 1348 | ||
1349 | |||
1287 | static void | 1350 | static void |
1288 | rise_up_after_value (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state, int next_state) | 1351 | rise_up_after_value (struct EXTRACTOR_PluginList *plugin, struct |
1352 | ebml_state *state, int next_state) | ||
1289 | { | 1353 | { |
1290 | int64_t offset; | 1354 | int64_t offset; |
1291 | state->state = EBML_READ_ELEMENT; | 1355 | state->state = EBML_READ_ELEMENT; |
1292 | offset = state->stack_top->position + state->stack_top->header_size + state->stack_top->size; | 1356 | offset = state->stack_top->position + state->stack_top->header_size |
1357 | + state->stack_top->size; | ||
1293 | free (ebml_stack_pop (state)); | 1358 | free (ebml_stack_pop (state)); |
1294 | state->next_state = next_state; | 1359 | state->next_state = next_state; |
1295 | pl_seek (plugin, offset, SEEK_SET); | 1360 | pl_seek (plugin, offset, SEEK_SET); |
1296 | } | 1361 | } |
1297 | 1362 | ||
1363 | |||
1298 | static void | 1364 | static void |
1299 | try_to_find_pos (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state) | 1365 | try_to_find_pos (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state) |
1300 | { | 1366 | { |
1301 | if (state->matroska_seeks != NULL) | 1367 | if (state->matroska_seeks != NULL) |
1302 | { | 1368 | { |
1303 | struct matroska_seek_list *el, *pos = NULL; | 1369 | struct matroska_seek_list *el, *pos = NULL; |
1304 | int64_t segment_position = pl_get_pos (plugin) - state->segment_contents_start; | 1370 | int64_t segment_position = pl_get_pos (plugin) |
1371 | - state->segment_contents_start; | ||
1305 | for (el = state->matroska_seeks; el != NULL; el = el->next) | 1372 | for (el = state->matroska_seeks; el != NULL; el = el->next) |
1306 | { | 1373 | { |
1307 | if (el->position <= segment_position) | 1374 | if (el->position <= segment_position) |
@@ -1314,8 +1381,10 @@ try_to_find_pos (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state) | |||
1314 | } | 1381 | } |
1315 | } | 1382 | } |
1316 | 1383 | ||
1384 | |||
1317 | static void | 1385 | static void |
1318 | maybe_seek_to_something_interesting (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state) | 1386 | maybe_seek_to_something_interesting (struct EXTRACTOR_PluginList *plugin, struct |
1387 | ebml_state *state) | ||
1319 | { | 1388 | { |
1320 | int64_t offset; | 1389 | int64_t offset; |
1321 | struct matroska_seek_list *el; | 1390 | struct matroska_seek_list *el; |
@@ -1350,12 +1419,14 @@ maybe_seek_to_something_interesting (struct EXTRACTOR_PluginList *plugin, struct | |||
1350 | * the one we've got from seek table. If it doesn't match - stop parsing the file. | 1419 | * the one we've got from seek table. If it doesn't match - stop parsing the file. |
1351 | */ | 1420 | */ |
1352 | #if DEBUG_EBML | 1421 | #if DEBUG_EBML |
1353 | printf ("Seeking from %llu to %llu\n", offset, el->position + state->segment_contents_start); | 1422 | printf ("Seeking from %llu to %llu\n", offset, el->position |
1423 | + state->segment_contents_start); | ||
1354 | #endif | 1424 | #endif |
1355 | pl_seek (plugin, el->position + state->segment_contents_start, SEEK_SET); | 1425 | pl_seek (plugin, el->position + state->segment_contents_start, SEEK_SET); |
1356 | } | 1426 | } |
1357 | } | 1427 | } |
1358 | 1428 | ||
1429 | |||
1359 | static void | 1430 | static void |
1360 | sort_seeks (struct ebml_state *state) | 1431 | sort_seeks (struct ebml_state *state) |
1361 | { | 1432 | { |
@@ -1363,7 +1434,7 @@ sort_seeks (struct ebml_state *state) | |||
1363 | int64_t position; | 1434 | int64_t position; |
1364 | struct matroska_seek_list *el; | 1435 | struct matroska_seek_list *el; |
1365 | char sorted = 0; | 1436 | char sorted = 0; |
1366 | while (!sorted) | 1437 | while (! sorted) |
1367 | { | 1438 | { |
1368 | sorted = 1; | 1439 | sorted = 1; |
1369 | for (el = state->matroska_seeks; el != NULL; el = el->next) | 1440 | for (el = state->matroska_seeks; el != NULL; el = el->next) |
@@ -1386,7 +1457,8 @@ sort_seeks (struct ebml_state *state) | |||
1386 | 1457 | ||
1387 | 1458 | ||
1388 | int | 1459 | int |
1389 | EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_MetaDataProcessor proc, void *proc_cls) | 1460 | EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, |
1461 | EXTRACTOR_MetaDataProcessor proc, void *proc_cls) | ||
1390 | { | 1462 | { |
1391 | uint64_t offset = 0; | 1463 | uint64_t offset = 0; |
1392 | ssize_t read_result; | 1464 | ssize_t read_result; |
@@ -1406,7 +1478,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1406 | 1478 | ||
1407 | if (plugin == NULL) | 1479 | if (plugin == NULL) |
1408 | return 1; | 1480 | return 1; |
1409 | 1481 | ||
1410 | state = EXTRACTOR_ebml_init_state_method (); | 1482 | state = EXTRACTOR_ebml_init_state_method (); |
1411 | if (state == NULL) | 1483 | if (state == NULL) |
1412 | return 1; | 1484 | return 1; |
@@ -1421,7 +1493,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1421 | return EXTRACTOR_ebml_discard_state_method (state); | 1493 | return EXTRACTOR_ebml_discard_state_method (state); |
1422 | case EBML_LOOKING_FOR_HEADER: | 1494 | case EBML_LOOKING_FOR_HEADER: |
1423 | offset = pl_get_pos (plugin); | 1495 | offset = pl_get_pos (plugin); |
1424 | sint_value = pl_read (plugin, &data, 1024*1024); | 1496 | sint_value = pl_read (plugin, &data, 1024 * 1024); |
1425 | if (sint_value < 4) | 1497 | if (sint_value < 4) |
1426 | return EXTRACTOR_ebml_discard_state_method (state); | 1498 | return EXTRACTOR_ebml_discard_state_method (state); |
1427 | start = NULL; | 1499 | start = NULL; |
@@ -1433,12 +1505,13 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1433 | offset = pl_get_pos (plugin) - 3; | 1505 | offset = pl_get_pos (plugin) - 3; |
1434 | if (offset != pl_seek (plugin, offset, SEEK_SET)) | 1506 | if (offset != pl_seek (plugin, offset, SEEK_SET)) |
1435 | return EXTRACTOR_ebml_discard_state_method (state); | 1507 | return EXTRACTOR_ebml_discard_state_method (state); |
1436 | sint_value = pl_read (plugin, &data, 1024*1024); | 1508 | sint_value = pl_read (plugin, &data, 1024 * 1024); |
1437 | if (sint_value < 4) | 1509 | if (sint_value < 4) |
1438 | return EXTRACTOR_ebml_discard_state_method (state); | 1510 | return EXTRACTOR_ebml_discard_state_method (state); |
1439 | } | 1511 | } |
1440 | } | 1512 | } |
1441 | if (offset + start - data != pl_seek (plugin, offset + start - data, SEEK_SET)) | 1513 | if (offset + start - data != pl_seek (plugin, offset + start - data, |
1514 | SEEK_SET)) | ||
1442 | return EXTRACTOR_ebml_discard_state_method (state); | 1515 | return EXTRACTOR_ebml_discard_state_method (state); |
1443 | state->state = EBML_READING_HEADER; | 1516 | state->state = EBML_READING_HEADER; |
1444 | break; | 1517 | break; |
@@ -1458,7 +1531,9 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1458 | } | 1531 | } |
1459 | state->state = EBML_READ_ELEMENT; | 1532 | state->state = EBML_READ_ELEMENT; |
1460 | state->next_state = EBML_READING_HEADER_ELEMENTS; | 1533 | state->next_state = EBML_READING_HEADER_ELEMENTS; |
1461 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_HEADER, EBML_BAD_STATE, EBML_FINISHED_READING_HEADER, EBML_BAD_STATE); | 1534 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, |
1535 | EBML_FINISHED_READING_HEADER, EBML_BAD_STATE, | ||
1536 | EBML_FINISHED_READING_HEADER, EBML_BAD_STATE); | ||
1462 | break; | 1537 | break; |
1463 | case EBML_READ_ELEMENT: | 1538 | case EBML_READ_ELEMENT: |
1464 | #if DEBUG_EBML | 1539 | #if DEBUG_EBML |
@@ -1475,19 +1550,14 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1475 | } | 1550 | } |
1476 | state->state = state->next_state; | 1551 | state->state = state->next_state; |
1477 | break; | 1552 | break; |
1478 | */ | 1553 | *//* while the following code crashes with SIGILL. |
1479 | /* while the following code crashes with SIGILL. | 1554 | *//* |
1480 | */ | ||
1481 | /* | ||
1482 | read_result = elementRead (plugin, &eID, &eSize); | 1555 | read_result = elementRead (plugin, &eID, &eSize); |
1483 | state->state = state->next_state; | 1556 | state->state = state->next_state; |
1484 | if (read_result < 0) | 1557 | if (read_result < 0) |
1485 | state->state = EBML_BAD_STATE; | 1558 | state->state = EBML_BAD_STATE; |
1486 | break; | 1559 | break; |
1487 | */ | 1560 | *//* but the following code works as intended *//* All three code snippets were compiled with -O0 */{ |
1488 | /* but the following code works as intended */ | ||
1489 | /* All three code snippets were compiled with -O0 */ | ||
1490 | { | ||
1491 | enum EBMLState next_state = state->next_state; | 1561 | enum EBMLState next_state = state->next_state; |
1492 | state->state = EBML_BAD_STATE; | 1562 | state->state = EBML_BAD_STATE; |
1493 | read_result = elementRead (plugin, &eID, (int64_t*) &eSize); | 1563 | read_result = elementRead (plugin, &eID, (int64_t*) &eSize); |
@@ -1506,7 +1576,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1506 | read_result = 0; | 1576 | read_result = 0; |
1507 | else | 1577 | else |
1508 | { | 1578 | { |
1509 | if (0 > (read_result = uintRead (plugin, state->stack_top->size, &uint_value))) | 1579 | if (0 > (read_result = uintRead (plugin, state->stack_top->size, |
1580 | &uint_value))) | ||
1510 | { | 1581 | { |
1511 | state->state = EBML_BAD_STATE; | 1582 | state->state = EBML_BAD_STATE; |
1512 | break; | 1583 | break; |
@@ -1516,7 +1587,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1516 | state->state = state->next_state; | 1587 | state->state = state->next_state; |
1517 | break; | 1588 | break; |
1518 | case EBML_READ_ID: | 1589 | case EBML_READ_ID: |
1519 | if (0 > (read_result = idRead (plugin, state->stack_top->size, &id_value))) | 1590 | if (0 > (read_result = idRead (plugin, state->stack_top->size, |
1591 | &id_value))) | ||
1520 | { | 1592 | { |
1521 | state->state = EBML_BAD_STATE; | 1593 | state->state = EBML_BAD_STATE; |
1522 | break; | 1594 | break; |
@@ -1534,7 +1606,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1534 | read_result = 0; | 1606 | read_result = 0; |
1535 | else | 1607 | else |
1536 | { | 1608 | { |
1537 | if (0 > (read_result = sintRead (plugin, state->stack_top->size, &sint_value))) | 1609 | if (0 > (read_result = sintRead (plugin, state->stack_top->size, |
1610 | &sint_value))) | ||
1538 | { | 1611 | { |
1539 | state->state = EBML_BAD_STATE; | 1612 | state->state = EBML_BAD_STATE; |
1540 | break; | 1613 | break; |
@@ -1554,7 +1627,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1554 | read_result = 0; | 1627 | read_result = 0; |
1555 | else | 1628 | else |
1556 | { | 1629 | { |
1557 | if (0 > (read_result = floatRead (plugin, state->stack_top->size, &float_value))) | 1630 | if (0 > (read_result = floatRead (plugin, state->stack_top->size, |
1631 | &float_value))) | ||
1558 | { | 1632 | { |
1559 | state->state = EBML_BAD_STATE; | 1633 | state->state = EBML_BAD_STATE; |
1560 | break; | 1634 | break; |
@@ -1571,7 +1645,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1571 | } | 1645 | } |
1572 | else | 1646 | else |
1573 | { | 1647 | { |
1574 | if (0 > (read_result = stringRead (plugin, state->stack_top->size, (char *) &string_value))) | 1648 | if (0 > (read_result = stringRead (plugin, state->stack_top->size, |
1649 | (char *) &string_value))) | ||
1575 | { | 1650 | { |
1576 | state->state = EBML_BAD_STATE; | 1651 | state->state = EBML_BAD_STATE; |
1577 | break; | 1652 | break; |
@@ -1581,7 +1656,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1581 | state->state = state->next_state; | 1656 | state->state = state->next_state; |
1582 | break; | 1657 | break; |
1583 | case EBML_READING_HEADER_ELEMENTS: | 1658 | case EBML_READING_HEADER_ELEMENTS: |
1584 | if (!check_result (plugin, read_result, state)) | 1659 | if (! check_result (plugin, read_result, state)) |
1585 | break; | 1660 | break; |
1586 | do_break = 0; | 1661 | do_break = 0; |
1587 | switch (eID) | 1662 | switch (eID) |
@@ -1609,10 +1684,13 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1609 | if (do_break) | 1684 | if (do_break) |
1610 | break; | 1685 | break; |
1611 | state->next_state = EBML_READING_HEADER_ELEMENT_VALUE; | 1686 | state->next_state = EBML_READING_HEADER_ELEMENT_VALUE; |
1612 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_HEADER_ELEMENTS, EBML_READ_ELEMENT, EBML_READING_HEADER_ELEMENTS); | 1687 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, |
1688 | EBML_BAD_STATE, EBML_READING_HEADER_ELEMENTS, | ||
1689 | EBML_READ_ELEMENT, | ||
1690 | EBML_READING_HEADER_ELEMENTS); | ||
1613 | break; | 1691 | break; |
1614 | case EBML_READING_HEADER_ELEMENT_VALUE: | 1692 | case EBML_READING_HEADER_ELEMENT_VALUE: |
1615 | if (!check_result (plugin, read_result, state)) | 1693 | if (! check_result (plugin, read_result, state)) |
1616 | break; | 1694 | break; |
1617 | 1695 | ||
1618 | switch (state->stack_top->id) | 1696 | switch (state->stack_top->id) |
@@ -1632,8 +1710,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1632 | * We also stop right here and do not assume that somewhere further | 1710 | * We also stop right here and do not assume that somewhere further |
1633 | * in the file there's another EBML header that is, maybe, readable | 1711 | * in the file there's another EBML header that is, maybe, readable |
1634 | * by us. If you think this is worth correcting - patches are welcome. | 1712 | * by us. If you think this is worth correcting - patches are welcome. |
1635 | */ | 1713 | */continue; |
1636 | continue; | ||
1637 | } | 1714 | } |
1638 | break; | 1715 | break; |
1639 | case EBMLID_MAX_ID_LENGTH: | 1716 | case EBMLID_MAX_ID_LENGTH: |
@@ -1658,7 +1735,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1658 | rise_up_after_value (plugin, state, EBML_READING_HEADER_ELEMENTS); | 1735 | rise_up_after_value (plugin, state, EBML_READING_HEADER_ELEMENTS); |
1659 | break; | 1736 | break; |
1660 | case EBML_FINISHED_READING_HEADER: | 1737 | case EBML_FINISHED_READING_HEADER: |
1661 | if (!state->valid_ebml) | 1738 | if (! state->valid_ebml) |
1662 | { | 1739 | { |
1663 | /* Header was invalid (lacking doctype). */ | 1740 | /* Header was invalid (lacking doctype). */ |
1664 | state->next_state = EBML_SKIP_UNTIL_NEXT_HEADER; | 1741 | state->next_state = EBML_SKIP_UNTIL_NEXT_HEADER; |
@@ -1680,8 +1757,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1680 | * metadata from it!), we do not care about these differences | 1757 | * metadata from it!), we do not care about these differences |
1681 | * (which means that this code will happily read webm files that do | 1758 | * (which means that this code will happily read webm files that do |
1682 | * not conform to Webm spec, but conform to Matroska spec). | 1759 | * not conform to Webm spec, but conform to Matroska spec). |
1683 | */ | 1760 | */state->next_state = EBML_READING_MATROSKA_SEGMENT; |
1684 | state->next_state = EBML_READING_MATROSKA_SEGMENT; | ||
1685 | } | 1761 | } |
1686 | else | 1762 | else |
1687 | { | 1763 | { |
@@ -1727,11 +1803,14 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1727 | state->state = EBML_READ_ELEMENT; | 1803 | state->state = EBML_READ_ELEMENT; |
1728 | state->next_state = EBML_READING_MATROSKA_SEGMENT_CONTENTS; | 1804 | state->next_state = EBML_READING_MATROSKA_SEGMENT_CONTENTS; |
1729 | clean_ebml_state_matroska_segment (state); | 1805 | clean_ebml_state_matroska_segment (state); |
1730 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READING_MATROSKA_SEGMENT, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT); | 1806 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, |
1807 | EBML_FINISHED_READING_MATROSKA_SEGMENT_CONTENTS, | ||
1808 | EBML_READING_MATROSKA_SEGMENT, EBML_READ_ELEMENT, | ||
1809 | EBML_READING_MATROSKA_SEGMENT); | ||
1731 | state->segment_contents_start = pl_get_pos (plugin); | 1810 | state->segment_contents_start = pl_get_pos (plugin); |
1732 | break; | 1811 | break; |
1733 | case EBML_READING_MATROSKA_SEGMENT_CONTENTS: | 1812 | case EBML_READING_MATROSKA_SEGMENT_CONTENTS: |
1734 | if (!check_result (plugin, read_result, state)) | 1813 | if (! check_result (plugin, read_result, state)) |
1735 | break; | 1814 | break; |
1736 | 1815 | ||
1737 | state->state = EBML_READ_ELEMENT; | 1816 | state->state = EBML_READ_ELEMENT; |
@@ -1739,20 +1818,40 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1739 | { | 1818 | { |
1740 | case MatroskaID_SeekHead: | 1819 | case MatroskaID_SeekHead: |
1741 | state->next_state = EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS; | 1820 | state->next_state = EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS; |
1742 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SEEK_HEAD_CONTENTS, EBML_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT_CONTENTS); | 1821 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
1822 | read_result, | ||
1823 | EBML_FINISHED_READING_MATROSKA_SEEK_HEAD_CONTENTS, | ||
1824 | EBML_READING_MATROSKA_SEGMENT_CONTENTS, | ||
1825 | EBML_READ_ELEMENT, | ||
1826 | EBML_READING_MATROSKA_SEGMENT_CONTENTS); | ||
1743 | break; | 1827 | break; |
1744 | case MatroskaID_Info: | 1828 | case MatroskaID_Info: |
1745 | state->next_state = EBML_READING_MATROSKA_INFO_CONTENTS; | 1829 | state->next_state = EBML_READING_MATROSKA_INFO_CONTENTS; |
1746 | clean_ebml_state_matroska_info (state); | 1830 | clean_ebml_state_matroska_info (state); |
1747 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_INFO_CONTENTS, EBML_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT_CONTENTS); | 1831 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
1832 | read_result, | ||
1833 | EBML_FINISHED_READING_MATROSKA_INFO_CONTENTS, | ||
1834 | EBML_READING_MATROSKA_SEGMENT_CONTENTS, | ||
1835 | EBML_READ_ELEMENT, | ||
1836 | EBML_READING_MATROSKA_SEGMENT_CONTENTS); | ||
1748 | break; | 1837 | break; |
1749 | case MatroskaID_Tracks: | 1838 | case MatroskaID_Tracks: |
1750 | state->next_state = EBML_READING_MATROSKA_TRACKS_CONTENTS; | 1839 | state->next_state = EBML_READING_MATROSKA_TRACKS_CONTENTS; |
1751 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TRACKS_CONTENTS, EBML_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT_CONTENTS); | 1840 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
1841 | read_result, | ||
1842 | EBML_FINISHED_READING_MATROSKA_TRACKS_CONTENTS, | ||
1843 | EBML_READING_MATROSKA_SEGMENT_CONTENTS, | ||
1844 | EBML_READ_ELEMENT, | ||
1845 | EBML_READING_MATROSKA_SEGMENT_CONTENTS); | ||
1752 | break; | 1846 | break; |
1753 | case MatroskaID_Tags: | 1847 | case MatroskaID_Tags: |
1754 | state->next_state = EBML_READING_MATROSKA_TAGS_CONTENTS; | 1848 | state->next_state = EBML_READING_MATROSKA_TAGS_CONTENTS; |
1755 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TAGS_CONTENTS, EBML_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT_CONTENTS); | 1849 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
1850 | read_result, | ||
1851 | EBML_FINISHED_READING_MATROSKA_TAGS_CONTENTS, | ||
1852 | EBML_READING_MATROSKA_SEGMENT_CONTENTS, | ||
1853 | EBML_READ_ELEMENT, | ||
1854 | EBML_READING_MATROSKA_SEGMENT_CONTENTS); | ||
1756 | break; | 1855 | break; |
1757 | default: | 1856 | default: |
1758 | if (maybe_rise_up (plugin, state, &do_break, read_result)) | 1857 | if (maybe_rise_up (plugin, state, &do_break, read_result)) |
@@ -1763,7 +1862,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1763 | } | 1862 | } |
1764 | break; | 1863 | break; |
1765 | case EBML_READING_MATROSKA_TAGS_CONTENTS: | 1864 | case EBML_READING_MATROSKA_TAGS_CONTENTS: |
1766 | if (!check_result (plugin, read_result, state)) | 1865 | if (! check_result (plugin, read_result, state)) |
1767 | break; | 1866 | break; |
1768 | state->state = EBML_READ_ELEMENT; | 1867 | state->state = EBML_READ_ELEMENT; |
1769 | switch (eID) | 1868 | switch (eID) |
@@ -1771,7 +1870,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1771 | case MatroskaID_Tags_Tag: | 1870 | case MatroskaID_Tags_Tag: |
1772 | state->next_state = EBML_READING_MATROSKA_TAG_CONTENTS; | 1871 | state->next_state = EBML_READING_MATROSKA_TAG_CONTENTS; |
1773 | clean_ebml_state_matroska_seek (state); | 1872 | clean_ebml_state_matroska_seek (state); |
1774 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TAG_CONTENTS, EBML_READING_MATROSKA_TAGS_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TAGS_CONTENTS); | 1873 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
1874 | read_result, | ||
1875 | EBML_FINISHED_READING_MATROSKA_TAG_CONTENTS, | ||
1876 | EBML_READING_MATROSKA_TAGS_CONTENTS, | ||
1877 | EBML_READ_ELEMENT, | ||
1878 | EBML_READING_MATROSKA_TAGS_CONTENTS); | ||
1775 | break; | 1879 | break; |
1776 | default: | 1880 | default: |
1777 | if (maybe_rise_up (plugin, state, &do_break, read_result)) | 1881 | if (maybe_rise_up (plugin, state, &do_break, read_result)) |
@@ -1781,7 +1885,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1781 | } | 1885 | } |
1782 | break; | 1886 | break; |
1783 | case EBML_READING_MATROSKA_TAG_CONTENTS: | 1887 | case EBML_READING_MATROSKA_TAG_CONTENTS: |
1784 | if (!check_result (plugin, read_result, state)) | 1888 | if (! check_result (plugin, read_result, state)) |
1785 | break; | 1889 | break; |
1786 | 1890 | ||
1787 | state->state = EBML_READ_ELEMENT; | 1891 | state->state = EBML_READ_ELEMENT; |
@@ -1793,7 +1897,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1793 | matroska_add_tag (state, NULL, NULL, NULL); | 1897 | matroska_add_tag (state, NULL, NULL, NULL); |
1794 | state->tag_current = state->tag_last; | 1898 | state->tag_current = state->tag_last; |
1795 | state->tag_tree = state->tag_current; | 1899 | state->tag_tree = state->tag_current; |
1796 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS, EBML_READING_MATROSKA_TAG_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TAG_CONTENTS); | 1900 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
1901 | read_result, | ||
1902 | EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS, | ||
1903 | EBML_READING_MATROSKA_TAG_CONTENTS, | ||
1904 | EBML_READ_ELEMENT, | ||
1905 | EBML_READING_MATROSKA_TAG_CONTENTS); | ||
1797 | break; | 1906 | break; |
1798 | default: | 1907 | default: |
1799 | if (maybe_rise_up (plugin, state, &do_break, read_result)) | 1908 | if (maybe_rise_up (plugin, state, &do_break, read_result)) |
@@ -1803,7 +1912,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1803 | } | 1912 | } |
1804 | break; | 1913 | break; |
1805 | case EBML_READING_MATROSKA_SIMPLETAG_CONTENTS: | 1914 | case EBML_READING_MATROSKA_SIMPLETAG_CONTENTS: |
1806 | if (!check_result (plugin, read_result, state)) | 1915 | if (! check_result (plugin, read_result, state)) |
1807 | break; | 1916 | break; |
1808 | 1917 | ||
1809 | do_break = 0; | 1918 | do_break = 0; |
@@ -1823,7 +1932,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1823 | state->next_state = EBML_READING_MATROSKA_SIMPLETAG_CONTENTS; | 1932 | state->next_state = EBML_READING_MATROSKA_SIMPLETAG_CONTENTS; |
1824 | matroska_add_tag (state, state->tag_current, NULL, NULL); | 1933 | matroska_add_tag (state, state->tag_current, NULL, NULL); |
1825 | state->tag_current = state->tag_last; | 1934 | state->tag_current = state->tag_last; |
1826 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS, EBML_READING_MATROSKA_SIMPLETAG_CONTENTS, EBML_READ_ELEMENT, EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS); | 1935 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
1936 | read_result, | ||
1937 | EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS, | ||
1938 | EBML_READING_MATROSKA_SIMPLETAG_CONTENTS, | ||
1939 | EBML_READ_ELEMENT, | ||
1940 | EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS); | ||
1827 | do_break = 1; | 1941 | do_break = 1; |
1828 | break; | 1942 | break; |
1829 | default: | 1943 | default: |
@@ -1838,10 +1952,14 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1838 | if (do_break) | 1952 | if (do_break) |
1839 | break; | 1953 | break; |
1840 | state->next_state = EBML_READING_MATROSKA_SIMPLETAG_CONTENTS_VALUE; | 1954 | state->next_state = EBML_READING_MATROSKA_SIMPLETAG_CONTENTS_VALUE; |
1841 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_SIMPLETAG_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SIMPLETAG_CONTENTS); | 1955 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, |
1956 | EBML_BAD_STATE, | ||
1957 | EBML_READING_MATROSKA_SIMPLETAG_CONTENTS, | ||
1958 | EBML_READ_ELEMENT, | ||
1959 | EBML_READING_MATROSKA_SIMPLETAG_CONTENTS); | ||
1842 | break; | 1960 | break; |
1843 | case EBML_READING_MATROSKA_SIMPLETAG_CONTENTS_VALUE: | 1961 | case EBML_READING_MATROSKA_SIMPLETAG_CONTENTS_VALUE: |
1844 | if (!check_result (plugin, read_result, state)) | 1962 | if (! check_result (plugin, read_result, state)) |
1845 | break; | 1963 | break; |
1846 | 1964 | ||
1847 | /* This breaks the specs, as there should be only one instance of each | 1965 | /* This breaks the specs, as there should be only one instance of each |
@@ -1861,10 +1979,11 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1861 | state->tag_current->string = strdup (string_value); | 1979 | state->tag_current->string = strdup (string_value); |
1862 | break; | 1980 | break; |
1863 | } | 1981 | } |
1864 | rise_up_after_value (plugin, state, EBML_READING_MATROSKA_SIMPLETAG_CONTENTS); | 1982 | rise_up_after_value (plugin, state, |
1983 | EBML_READING_MATROSKA_SIMPLETAG_CONTENTS); | ||
1865 | break; | 1984 | break; |
1866 | case EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS: | 1985 | case EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS: |
1867 | if (!check_result (plugin, read_result, state)) | 1986 | if (! check_result (plugin, read_result, state)) |
1868 | break; | 1987 | break; |
1869 | 1988 | ||
1870 | state->state = EBML_READ_ELEMENT; | 1989 | state->state = EBML_READ_ELEMENT; |
@@ -1873,7 +1992,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1873 | case MatroskaID_Seek: | 1992 | case MatroskaID_Seek: |
1874 | state->next_state = EBML_READING_MATROSKA_SEEK_CONTENTS; | 1993 | state->next_state = EBML_READING_MATROSKA_SEEK_CONTENTS; |
1875 | clean_ebml_state_matroska_seek (state); | 1994 | clean_ebml_state_matroska_seek (state); |
1876 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SEEK_CONTENTS, EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS); | 1995 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
1996 | read_result, | ||
1997 | EBML_FINISHED_READING_MATROSKA_SEEK_CONTENTS, | ||
1998 | EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS, | ||
1999 | EBML_READ_ELEMENT, | ||
2000 | EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS); | ||
1877 | break; | 2001 | break; |
1878 | default: | 2002 | default: |
1879 | if (maybe_rise_up (plugin, state, &do_break, read_result)) | 2003 | if (maybe_rise_up (plugin, state, &do_break, read_result)) |
@@ -1883,7 +2007,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1883 | } | 2007 | } |
1884 | break; | 2008 | break; |
1885 | case EBML_READING_MATROSKA_SEEK_CONTENTS: | 2009 | case EBML_READING_MATROSKA_SEEK_CONTENTS: |
1886 | if (!check_result (plugin, read_result, state)) | 2010 | if (! check_result (plugin, read_result, state)) |
1887 | break; | 2011 | break; |
1888 | 2012 | ||
1889 | do_break = 0; | 2013 | do_break = 0; |
@@ -1907,10 +2031,13 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1907 | if (do_break) | 2031 | if (do_break) |
1908 | break; | 2032 | break; |
1909 | state->next_state = EBML_READING_MATROSKA_SEEK_CONTENTS_VALUE; | 2033 | state->next_state = EBML_READING_MATROSKA_SEEK_CONTENTS_VALUE; |
1910 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_SEEK_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEEK_CONTENTS); | 2034 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, |
2035 | EBML_BAD_STATE, EBML_READING_MATROSKA_SEEK_CONTENTS, | ||
2036 | EBML_READ_ELEMENT, | ||
2037 | EBML_READING_MATROSKA_SEEK_CONTENTS); | ||
1911 | break; | 2038 | break; |
1912 | case EBML_READING_MATROSKA_SEEK_CONTENTS_VALUE: | 2039 | case EBML_READING_MATROSKA_SEEK_CONTENTS_VALUE: |
1913 | if (!check_result (plugin, read_result, state)) | 2040 | if (! check_result (plugin, read_result, state)) |
1914 | break; | 2041 | break; |
1915 | 2042 | ||
1916 | /* This breaks the specs, as there should be only one instance of each | 2043 | /* This breaks the specs, as there should be only one instance of each |
@@ -1929,7 +2056,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1929 | rise_up_after_value (plugin, state, EBML_READING_MATROSKA_SEEK_CONTENTS); | 2056 | rise_up_after_value (plugin, state, EBML_READING_MATROSKA_SEEK_CONTENTS); |
1930 | break; | 2057 | break; |
1931 | case EBML_READING_MATROSKA_TRACKS_CONTENTS: | 2058 | case EBML_READING_MATROSKA_TRACKS_CONTENTS: |
1932 | if (!check_result (plugin, read_result, state)) | 2059 | if (! check_result (plugin, read_result, state)) |
1933 | break; | 2060 | break; |
1934 | 2061 | ||
1935 | state->state = EBML_READ_ELEMENT; | 2062 | state->state = EBML_READ_ELEMENT; |
@@ -1938,7 +2065,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1938 | case MatroskaID_Tracks_TrackEntry: | 2065 | case MatroskaID_Tracks_TrackEntry: |
1939 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS; | 2066 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS; |
1940 | clean_ebml_state_matroska_track (state); | 2067 | clean_ebml_state_matroska_track (state); |
1941 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_CONTENTS, EBML_READING_MATROSKA_TRACKS_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACKS_CONTENTS); | 2068 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
2069 | read_result, | ||
2070 | EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_CONTENTS, | ||
2071 | EBML_READING_MATROSKA_TRACKS_CONTENTS, | ||
2072 | EBML_READ_ELEMENT, | ||
2073 | EBML_READING_MATROSKA_TRACKS_CONTENTS); | ||
1942 | break; | 2074 | break; |
1943 | default: | 2075 | default: |
1944 | if (maybe_rise_up (plugin, state, &do_break, read_result)) | 2076 | if (maybe_rise_up (plugin, state, &do_break, read_result)) |
@@ -1948,7 +2080,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1948 | } | 2080 | } |
1949 | break; | 2081 | break; |
1950 | case EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS: | 2082 | case EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS: |
1951 | if (!check_result (plugin, read_result, state)) | 2083 | if (! check_result (plugin, read_result, state)) |
1952 | break; | 2084 | break; |
1953 | 2085 | ||
1954 | do_break = 0; | 2086 | do_break = 0; |
@@ -1967,14 +2099,24 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1967 | state->state = EBML_READ_ELEMENT; | 2099 | state->state = EBML_READ_ELEMENT; |
1968 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS; | 2100 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS; |
1969 | clean_ebml_state_matroska_track_video (state); | 2101 | clean_ebml_state_matroska_track_video (state); |
1970 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); | 2102 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
2103 | read_result, | ||
2104 | EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS, | ||
2105 | EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, | ||
2106 | EBML_READ_ELEMENT, | ||
2107 | EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); | ||
1971 | do_break = 1; | 2108 | do_break = 1; |
1972 | break; | 2109 | break; |
1973 | case MatroskaID_Tracks_Audio: | 2110 | case MatroskaID_Tracks_Audio: |
1974 | state->state = EBML_READ_ELEMENT; | 2111 | state->state = EBML_READ_ELEMENT; |
1975 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS; | 2112 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS; |
1976 | clean_ebml_state_matroska_track_audio (state); | 2113 | clean_ebml_state_matroska_track_audio (state); |
1977 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); | 2114 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, |
2115 | read_result, | ||
2116 | EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS, | ||
2117 | EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, | ||
2118 | EBML_READ_ELEMENT, | ||
2119 | EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); | ||
1978 | do_break = 1; | 2120 | do_break = 1; |
1979 | break; | 2121 | break; |
1980 | default: | 2122 | default: |
@@ -1989,10 +2131,14 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
1989 | if (do_break) | 2131 | if (do_break) |
1990 | break; | 2132 | break; |
1991 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS_VALUE; | 2133 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS_VALUE; |
1992 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); | 2134 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, |
2135 | EBML_BAD_STATE, | ||
2136 | EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, | ||
2137 | EBML_READ_ELEMENT, | ||
2138 | EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); | ||
1993 | break; | 2139 | break; |
1994 | case EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS: | 2140 | case EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS: |
1995 | if (!check_result (plugin, read_result, state)) | 2141 | if (! check_result (plugin, read_result, state)) |
1996 | break; | 2142 | break; |
1997 | 2143 | ||
1998 | do_break = 0; | 2144 | do_break = 0; |
@@ -2017,11 +2163,16 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2017 | } | 2163 | } |
2018 | if (do_break) | 2164 | if (do_break) |
2019 | break; | 2165 | break; |
2020 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS_VALUE; | 2166 | state->next_state = |
2021 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS); | 2167 | EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS_VALUE; |
2168 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, | ||
2169 | EBML_BAD_STATE, | ||
2170 | EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS, | ||
2171 | EBML_READ_ELEMENT, | ||
2172 | EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS); | ||
2022 | break; | 2173 | break; |
2023 | case EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS_VALUE: | 2174 | case EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS_VALUE: |
2024 | if (!check_result (plugin, read_result, state)) | 2175 | if (! check_result (plugin, read_result, state)) |
2025 | break; | 2176 | break; |
2026 | 2177 | ||
2027 | /* This breaks the specs, as there should be only one instance of each | 2178 | /* This breaks the specs, as there should be only one instance of each |
@@ -2043,10 +2194,11 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2043 | state->matroska_track_audio_bit_depth = uint_value; | 2194 | state->matroska_track_audio_bit_depth = uint_value; |
2044 | break; | 2195 | break; |
2045 | } | 2196 | } |
2046 | rise_up_after_value (plugin, state, EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS); | 2197 | rise_up_after_value (plugin, state, |
2198 | EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS); | ||
2047 | break; | 2199 | break; |
2048 | case EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS: | 2200 | case EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS: |
2049 | if (!check_result (plugin, read_result, state)) | 2201 | if (! check_result (plugin, read_result, state)) |
2050 | break; | 2202 | break; |
2051 | 2203 | ||
2052 | do_break = 0; | 2204 | do_break = 0; |
@@ -2072,11 +2224,16 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2072 | } | 2224 | } |
2073 | if (do_break) | 2225 | if (do_break) |
2074 | break; | 2226 | break; |
2075 | state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS_VALUE; | 2227 | state->next_state = |
2076 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS); | 2228 | EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS_VALUE; |
2229 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, | ||
2230 | EBML_BAD_STATE, | ||
2231 | EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS, | ||
2232 | EBML_READ_ELEMENT, | ||
2233 | EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS); | ||
2077 | break; | 2234 | break; |
2078 | case EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS_VALUE: | 2235 | case EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS_VALUE: |
2079 | if (!check_result (plugin, read_result, state)) | 2236 | if (! check_result (plugin, read_result, state)) |
2080 | break; | 2237 | break; |
2081 | 2238 | ||
2082 | /* This breaks the specs, as there should be only one instance of each | 2239 | /* This breaks the specs, as there should be only one instance of each |
@@ -2107,10 +2264,11 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2107 | state->matroska_track_video_display_unit = uint_value; | 2264 | state->matroska_track_video_display_unit = uint_value; |
2108 | break; | 2265 | break; |
2109 | } | 2266 | } |
2110 | rise_up_after_value (plugin, state, EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS); | 2267 | rise_up_after_value (plugin, state, |
2268 | EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS); | ||
2111 | break; | 2269 | break; |
2112 | case EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS_VALUE: | 2270 | case EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS_VALUE: |
2113 | if (!check_result (plugin, read_result, state)) | 2271 | if (! check_result (plugin, read_result, state)) |
2114 | break; | 2272 | break; |
2115 | 2273 | ||
2116 | /* This breaks the specs, as there should be only one instance of each | 2274 | /* This breaks the specs, as there should be only one instance of each |
@@ -2143,10 +2301,11 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2143 | state->matroska_track_codec_name = strdup (string_value); | 2301 | state->matroska_track_codec_name = strdup (string_value); |
2144 | break; /* UTF-8-encoded. A human-readable string specifying the codec. */ | 2302 | break; /* UTF-8-encoded. A human-readable string specifying the codec. */ |
2145 | } | 2303 | } |
2146 | rise_up_after_value (plugin, state, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); | 2304 | rise_up_after_value (plugin, state, |
2305 | EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); | ||
2147 | break; | 2306 | break; |
2148 | case EBML_READING_MATROSKA_INFO_CONTENTS: | 2307 | case EBML_READING_MATROSKA_INFO_CONTENTS: |
2149 | if (!check_result (plugin, read_result, state)) | 2308 | if (! check_result (plugin, read_result, state)) |
2150 | break; | 2309 | break; |
2151 | 2310 | ||
2152 | do_break = 0; | 2311 | do_break = 0; |
@@ -2178,10 +2337,13 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2178 | if (do_break) | 2337 | if (do_break) |
2179 | break; | 2338 | break; |
2180 | state->next_state = EBML_READING_MATROSKA_INFO_CONTENTS_VALUE; | 2339 | state->next_state = EBML_READING_MATROSKA_INFO_CONTENTS_VALUE; |
2181 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_INFO_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_INFO_CONTENTS); | 2340 | ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, |
2341 | EBML_BAD_STATE, EBML_READING_MATROSKA_INFO_CONTENTS, | ||
2342 | EBML_READ_ELEMENT, | ||
2343 | EBML_READING_MATROSKA_INFO_CONTENTS); | ||
2182 | break; | 2344 | break; |
2183 | case EBML_READING_MATROSKA_INFO_CONTENTS_VALUE: | 2345 | case EBML_READING_MATROSKA_INFO_CONTENTS_VALUE: |
2184 | if (!check_result (plugin, read_result, state)) | 2346 | if (! check_result (plugin, read_result, state)) |
2185 | break; | 2347 | break; |
2186 | 2348 | ||
2187 | /* This breaks the specs, as there should be only one instance of each | 2349 | /* This breaks the specs, as there should be only one instance of each |
@@ -2219,7 +2381,10 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2219 | rise_up_after_value (plugin, state, EBML_READING_MATROSKA_INFO_CONTENTS); | 2381 | rise_up_after_value (plugin, state, EBML_READING_MATROSKA_INFO_CONTENTS); |
2220 | break; | 2382 | break; |
2221 | case EBML_FINISHED_READING_MATROSKA_INFO_CONTENTS: | 2383 | case EBML_FINISHED_READING_MATROSKA_INFO_CONTENTS: |
2222 | if (state->stack_top != NULL && pl_get_pos (plugin) >= state->stack_top->position + state->stack_top->header_size + state->stack_top->size) | 2384 | if ((state->stack_top != NULL) && (pl_get_pos (plugin) >= |
2385 | state->stack_top->position | ||
2386 | + state->stack_top->header_size | ||
2387 | + state->stack_top->size) ) | ||
2223 | report_state (state, proc, proc_cls); | 2388 | report_state (state, proc, proc_cls); |
2224 | maybe_seek_to_something_interesting (plugin, state); | 2389 | maybe_seek_to_something_interesting (plugin, state); |
2225 | state->state = EBML_READ_ELEMENT; | 2390 | state->state = EBML_READ_ELEMENT; |
@@ -2227,7 +2392,10 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2227 | free (ebml_stack_pop (state)); | 2392 | free (ebml_stack_pop (state)); |
2228 | break; | 2393 | break; |
2229 | case EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_CONTENTS: | 2394 | case EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_CONTENTS: |
2230 | if (state->stack_top != NULL && pl_get_pos (plugin) >= state->stack_top->position + state->stack_top->header_size + state->stack_top->size) | 2395 | if ((state->stack_top != NULL) && (pl_get_pos (plugin) >= |
2396 | state->stack_top->position | ||
2397 | + state->stack_top->header_size | ||
2398 | + state->stack_top->size) ) | ||
2231 | report_state (state, proc, proc_cls); | 2399 | report_state (state, proc, proc_cls); |
2232 | state->state = EBML_READ_ELEMENT; | 2400 | state->state = EBML_READ_ELEMENT; |
2233 | state->next_state = state->stack_top->prev_state; | 2401 | state->next_state = state->stack_top->prev_state; |
@@ -2235,7 +2403,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me | |||
2235 | break; | 2403 | break; |
2236 | case EBML_FINISHED_READING_MATROSKA_SEEK_CONTENTS: | 2404 | case EBML_FINISHED_READING_MATROSKA_SEEK_CONTENTS: |
2237 | if ((state->matroska_seek_id != 0) && | 2405 | if ((state->matroska_seek_id != 0) && |
2238 | ((state->matroska_seek_position > 0) || state->matroska_seeks_tail == NULL)) | 2406 | ((state->matroska_seek_position > 0) || (state->matroska_seeks_tail == |
2407 | NULL) )) | ||
2239 | { | 2408 | { |
2240 | struct matroska_seek_list *el; | 2409 | struct matroska_seek_list *el; |
2241 | el = malloc (sizeof (struct matroska_seek_list)); | 2410 | el = malloc (sizeof (struct matroska_seek_list)); |
diff --git a/src/plugins/old/elf_extractor.c b/src/plugins/old/elf_extractor.c index 0a14736..9c35e7c 100644 --- a/src/plugins/old/elf_extractor.c +++ b/src/plugins/old/elf_extractor.c | |||
@@ -26,7 +26,7 @@ | |||
26 | typedef uint32_t Elf32_Addr; | 26 | typedef uint32_t Elf32_Addr; |
27 | typedef uint16_t Elf32_Half; | 27 | typedef uint16_t Elf32_Half; |
28 | typedef uint32_t Elf32_Off; | 28 | typedef uint32_t Elf32_Off; |
29 | typedef int32_t Elf32_Sword; | 29 | typedef int32_t Elf32_Sword; |
30 | typedef uint32_t Elf32_Word; | 30 | typedef uint32_t Elf32_Word; |
31 | 31 | ||
32 | typedef uint16_t Elf64_Half; | 32 | typedef uint16_t Elf64_Half; |
@@ -64,57 +64,58 @@ typedef struct | |||
64 | #define ELF_HEADER_SIZE sizeof (Elf32_Ehdr) | 64 | #define ELF_HEADER_SIZE sizeof (Elf32_Ehdr) |
65 | 65 | ||
66 | #define ELF_HEADER_FIELDS(p) \ | 66 | #define ELF_HEADER_FIELDS(p) \ |
67 | &(p)->e_type, \ | 67 | & (p)->e_type, \ |
68 | &(p)->e_machine, \ | 68 | &(p)->e_machine, \ |
69 | &(p)->e_version, \ | 69 | &(p)->e_version, \ |
70 | &(p)->e_entry, \ | 70 | &(p)->e_entry, \ |
71 | &(p)->e_phoff, \ | 71 | &(p)->e_phoff, \ |
72 | &(p)->e_shoff, \ | 72 | &(p)->e_shoff, \ |
73 | &(p)->e_flags, \ | 73 | &(p)->e_flags, \ |
74 | &(p)->e_ehsize, \ | 74 | &(p)->e_ehsize, \ |
75 | &(p)->e_phensize, \ | 75 | &(p)->e_phensize, \ |
76 | &(p)->e_phnum, \ | 76 | &(p)->e_phnum, \ |
77 | &(p)->e_shentsize, \ | 77 | &(p)->e_shentsize, \ |
78 | &(p)->e_shnum, \ | 78 | &(p)->e_shnum, \ |
79 | &(p)->e_shstrndx | 79 | &(p)->e_shstrndx |
80 | static char *ELF_HEADER_SPECS[] = { | 80 | static char *ELF_HEADER_SPECS[] = { |
81 | "hhwwwwwhhhhhh", | 81 | "hhwwwwwhhhhhh", |
82 | "HHWWWWWHHHHHH", | 82 | "HHWWWWWHHHHHH", |
83 | }; | 83 | }; |
84 | 84 | ||
85 | typedef struct { | 85 | typedef struct |
86 | Elf64_Half e_type; | 86 | { |
87 | Elf64_Half e_machine; | 87 | Elf64_Half e_type; |
88 | Elf64_Word e_version; | 88 | Elf64_Half e_machine; |
89 | Elf64_Addr e_entry; | 89 | Elf64_Word e_version; |
90 | Elf64_Off e_phoff; | 90 | Elf64_Addr e_entry; |
91 | Elf64_Off e_shoff; | 91 | Elf64_Off e_phoff; |
92 | Elf64_Word e_flags; | 92 | Elf64_Off e_shoff; |
93 | Elf64_Half e_ehsize; | 93 | Elf64_Word e_flags; |
94 | Elf64_Half e_phensize; | 94 | Elf64_Half e_ehsize; |
95 | Elf64_Half e_phnum; | 95 | Elf64_Half e_phensize; |
96 | Elf64_Half e_shentsize; | 96 | Elf64_Half e_phnum; |
97 | Elf64_Half e_shnum; | 97 | Elf64_Half e_shentsize; |
98 | Elf64_Half e_shstrndx; | 98 | Elf64_Half e_shnum; |
99 | Elf64_Half e_shstrndx; | ||
99 | } Elf64_Ehdr; | 100 | } Elf64_Ehdr; |
100 | 101 | ||
101 | /* elf-header minus e_ident */ | 102 | /* elf-header minus e_ident */ |
102 | #define ELF64_HEADER_SIZE sizeof (Elf64_Ehdr) | 103 | #define ELF64_HEADER_SIZE sizeof (Elf64_Ehdr) |
103 | 104 | ||
104 | #define ELF64_HEADER_FIELDS(p) \ | 105 | #define ELF64_HEADER_FIELDS(p) \ |
105 | &(p)->e_type, \ | 106 | & (p)->e_type, \ |
106 | &(p)->e_machine, \ | 107 | &(p)->e_machine, \ |
107 | &(p)->e_version, \ | 108 | &(p)->e_version, \ |
108 | &(p)->e_entry, \ | 109 | &(p)->e_entry, \ |
109 | &(p)->e_phoff, \ | 110 | &(p)->e_phoff, \ |
110 | &(p)->e_shoff, \ | 111 | &(p)->e_shoff, \ |
111 | &(p)->e_flags, \ | 112 | &(p)->e_flags, \ |
112 | &(p)->e_ehsize, \ | 113 | &(p)->e_ehsize, \ |
113 | &(p)->e_phensize, \ | 114 | &(p)->e_phensize, \ |
114 | &(p)->e_phnum, \ | 115 | &(p)->e_phnum, \ |
115 | &(p)->e_shentsize, \ | 116 | &(p)->e_shentsize, \ |
116 | &(p)->e_shnum, \ | 117 | &(p)->e_shnum, \ |
117 | &(p)->e_shstrndx | 118 | &(p)->e_shstrndx |
118 | static char *ELF64_HEADER_SPECS[] = { | 119 | static char *ELF64_HEADER_SPECS[] = { |
119 | "hhwxxxwhhhhhh", | 120 | "hhwxxxwhhhhhh", |
120 | "HHWXXXWHHHHHH", | 121 | "HHWXXXWHHHHHH", |
@@ -137,16 +138,16 @@ typedef struct | |||
137 | #define ELF_SECTION_SIZE 40 | 138 | #define ELF_SECTION_SIZE 40 |
138 | 139 | ||
139 | #define ELF_SECTION_FIELDS(p) \ | 140 | #define ELF_SECTION_FIELDS(p) \ |
140 | &(p)->sh_name, \ | 141 | & (p)->sh_name, \ |
141 | &(p)->sh_type, \ | 142 | &(p)->sh_type, \ |
142 | &(p)->sh_flags, \ | 143 | &(p)->sh_flags, \ |
143 | &(p)->sh_addr, \ | 144 | &(p)->sh_addr, \ |
144 | &(p)->sh_offset, \ | 145 | &(p)->sh_offset, \ |
145 | &(p)->sh_size, \ | 146 | &(p)->sh_size, \ |
146 | &(p)->sh_link, \ | 147 | &(p)->sh_link, \ |
147 | &(p)->sh_info, \ | 148 | &(p)->sh_info, \ |
148 | &(p)->sh_addralign, \ | 149 | &(p)->sh_addralign, \ |
149 | &(p)->sh_entsize | 150 | &(p)->sh_entsize |
150 | static char *ELF_SECTION_SPECS[] = { | 151 | static char *ELF_SECTION_SPECS[] = { |
151 | "wwwwwwwwww", | 152 | "wwwwwwwwww", |
152 | "WWWWWWWWWW", | 153 | "WWWWWWWWWW", |
@@ -164,15 +165,15 @@ typedef struct | |||
164 | Elf32_Word p_align; | 165 | Elf32_Word p_align; |
165 | } Elf32_Phdr; | 166 | } Elf32_Phdr; |
166 | #define ELF_PDHR_SIZE 32 | 167 | #define ELF_PDHR_SIZE 32 |
167 | #define ELF_PHDR_FIELDS(p) \ | 168 | #define ELF_PHDR_FIELDS(p) \ |
168 | &(p)->p_type, \ | 169 | & (p)->p_type, \ |
169 | &(p)->p_offset, \ | 170 | &(p)->p_offset, \ |
170 | &(p)->p_vaddr, \ | 171 | &(p)->p_vaddr, \ |
171 | &(p)->p_paddr, \ | 172 | &(p)->p_paddr, \ |
172 | &(p)->p_filesz, \ | 173 | &(p)->p_filesz, \ |
173 | &(p)->p_memsz, \ | 174 | &(p)->p_memsz, \ |
174 | &(p)->p_flags, \ | 175 | &(p)->p_flags, \ |
175 | &(p)->p_align | 176 | &(p)->p_align |
176 | static char *ELF_PHDR_SPECS[] = { | 177 | static char *ELF_PHDR_SPECS[] = { |
177 | "wwwwwwww", | 178 | "wwwwwwww", |
178 | "WWWWWWWW", | 179 | "WWWWWWWW", |
@@ -188,9 +189,9 @@ typedef struct | |||
188 | } d_un; | 189 | } d_un; |
189 | } Elf32_Dyn; | 190 | } Elf32_Dyn; |
190 | #define ELF_DYN_SIZE 8 | 191 | #define ELF_DYN_SIZE 8 |
191 | #define ELF_DYN_FIELDS(p) \ | 192 | #define ELF_DYN_FIELDS(p) \ |
192 | &(p)->d_tag, \ | 193 | & (p)->d_tag, \ |
193 | &(p)->d_un | 194 | &(p)->d_un |
194 | static char *ELF_DYN_SPECS[] = { | 195 | static char *ELF_DYN_SPECS[] = { |
195 | "ww", | 196 | "ww", |
196 | "WW", | 197 | "WW", |
@@ -292,8 +293,6 @@ static char *ELF_DYN_SPECS[] = { | |||
292 | #define PT_HIPROC 0x7fffffff | 293 | #define PT_HIPROC 0x7fffffff |
293 | 294 | ||
294 | 295 | ||
295 | |||
296 | |||
297 | #define ELFCLASSNONE 0 | 296 | #define ELFCLASSNONE 0 |
298 | #define ELFCLASS32 1 | 297 | #define ELFCLASS32 1 |
299 | #define ELFCLASS64 2 | 298 | #define ELFCLASS64 2 |
@@ -312,23 +311,24 @@ static int | |||
312 | getByteorder (char ei_data) | 311 | getByteorder (char ei_data) |
313 | { | 312 | { |
314 | if (ei_data == ELFDATA2LSB) | 313 | if (ei_data == ELFDATA2LSB) |
315 | { | 314 | { |
316 | #if __BYTE_ORDER == __BIG_ENDIAN | 315 | #if __BYTE_ORDER == __BIG_ENDIAN |
317 | return 1; | 316 | return 1; |
318 | #else | 317 | #else |
319 | return 0; | 318 | return 0; |
320 | #endif | 319 | #endif |
321 | } | 320 | } |
322 | else | 321 | else |
323 | { | 322 | { |
324 | #if __BYTE_ORDER == __BIG_ENDIAN | 323 | #if __BYTE_ORDER == __BIG_ENDIAN |
325 | return 0; | 324 | return 0; |
326 | #else | 325 | #else |
327 | return 1; | 326 | return 1; |
328 | #endif | 327 | #endif |
329 | } | 328 | } |
330 | } | 329 | } |
331 | 330 | ||
331 | |||
332 | /** | 332 | /** |
333 | * | 333 | * |
334 | * @return 0 on success, -1 on error | 334 | * @return 0 on success, -1 on error |
@@ -336,17 +336,18 @@ getByteorder (char ei_data) | |||
336 | static int | 336 | static int |
337 | getSectionHdr (const char *data, | 337 | getSectionHdr (const char *data, |
338 | size_t size, | 338 | size_t size, |
339 | Elf32_Ehdr * ehdr, Elf32_Half idx, Elf32_Shdr * ret) | 339 | Elf32_Ehdr *ehdr, Elf32_Half idx, Elf32_Shdr *ret) |
340 | { | 340 | { |
341 | if (ehdr->e_shnum <= idx) | 341 | if (ehdr->e_shnum <= idx) |
342 | return -1; | 342 | return -1; |
343 | 343 | ||
344 | EXTRACTOR_common_cat_unpack (&data[ehdr->e_shoff + ehdr->e_shentsize * idx], | 344 | EXTRACTOR_common_cat_unpack (&data[ehdr->e_shoff + ehdr->e_shentsize * idx], |
345 | ELF_SECTION_SPECS[getByteorder (data[EI_CLASS])], | 345 | ELF_SECTION_SPECS[getByteorder (data[EI_CLASS])], |
346 | ELF_SECTION_FIELDS (ret)); | 346 | ELF_SECTION_FIELDS (ret)); |
347 | return 0; | 347 | return 0; |
348 | } | 348 | } |
349 | 349 | ||
350 | |||
350 | /** | 351 | /** |
351 | * | 352 | * |
352 | * @return 0 on success, -1 on error | 353 | * @return 0 on success, -1 on error |
@@ -354,17 +355,18 @@ getSectionHdr (const char *data, | |||
354 | static int | 355 | static int |
355 | getDynTag (const char *data, | 356 | getDynTag (const char *data, |
356 | size_t size, | 357 | size_t size, |
357 | Elf32_Ehdr * ehdr, | 358 | Elf32_Ehdr *ehdr, |
358 | Elf32_Off off, Elf32_Word osize, unsigned int idx, Elf32_Dyn * ret) | 359 | Elf32_Off off, Elf32_Word osize, unsigned int idx, Elf32_Dyn *ret) |
359 | { | 360 | { |
360 | if ((off + osize > size) || ((idx + 1) * ELF_DYN_SIZE > osize)) | 361 | if ((off + osize > size) || ((idx + 1) * ELF_DYN_SIZE > osize)) |
361 | return -1; | 362 | return -1; |
362 | EXTRACTOR_common_cat_unpack (&data[off + idx * ELF_DYN_SIZE], | 363 | EXTRACTOR_common_cat_unpack (&data[off + idx * ELF_DYN_SIZE], |
363 | ELF_DYN_SPECS[getByteorder (data[EI_CLASS])], | 364 | ELF_DYN_SPECS[getByteorder (data[EI_CLASS])], |
364 | ELF_DYN_FIELDS (ret)); | 365 | ELF_DYN_FIELDS (ret)); |
365 | return 0; | 366 | return 0; |
366 | } | 367 | } |
367 | 368 | ||
369 | |||
368 | /** | 370 | /** |
369 | * | 371 | * |
370 | * @return 0 on success, -1 on error | 372 | * @return 0 on success, -1 on error |
@@ -372,26 +374,27 @@ getDynTag (const char *data, | |||
372 | static int | 374 | static int |
373 | getProgramHdr (const char *data, | 375 | getProgramHdr (const char *data, |
374 | size_t size, | 376 | size_t size, |
375 | Elf32_Ehdr * ehdr, Elf32_Half idx, Elf32_Phdr * ret) | 377 | Elf32_Ehdr *ehdr, Elf32_Half idx, Elf32_Phdr *ret) |
376 | { | 378 | { |
377 | if (ehdr->e_phnum <= idx) | 379 | if (ehdr->e_phnum <= idx) |
378 | return -1; | 380 | return -1; |
379 | 381 | ||
380 | EXTRACTOR_common_cat_unpack (&data[ehdr->e_phoff + ehdr->e_phensize * idx], | 382 | EXTRACTOR_common_cat_unpack (&data[ehdr->e_phoff + ehdr->e_phensize * idx], |
381 | ELF_PHDR_SPECS[getByteorder (data[EI_CLASS])], | 383 | ELF_PHDR_SPECS[getByteorder (data[EI_CLASS])], |
382 | ELF_PHDR_FIELDS (ret)); | 384 | ELF_PHDR_FIELDS (ret)); |
383 | return 0; | 385 | return 0; |
384 | } | 386 | } |
385 | 387 | ||
388 | |||
386 | /** | 389 | /** |
387 | * Parse ELF header. | 390 | * Parse ELF header. |
388 | * @return 0 on success for 32 bit, 1 on success for 64 bit, -1 on error | 391 | * @return 0 on success for 32 bit, 1 on success for 64 bit, -1 on error |
389 | */ | 392 | */ |
390 | static int | 393 | static int |
391 | getELFHdr (const char *data, | 394 | getELFHdr (const char *data, |
392 | size_t size, | 395 | size_t size, |
393 | Elf32_Ehdr * ehdr, | 396 | Elf32_Ehdr *ehdr, |
394 | Elf64_Ehdr * ehdr64) | 397 | Elf64_Ehdr *ehdr64) |
395 | { | 398 | { |
396 | /* catlib */ | 399 | /* catlib */ |
397 | if (size < EI_NIDENT) | 400 | if (size < EI_NIDENT) |
@@ -400,43 +403,47 @@ getELFHdr (const char *data, | |||
400 | return -1; /* not an elf */ | 403 | return -1; /* not an elf */ |
401 | 404 | ||
402 | switch (data[EI_CLASS]) | 405 | switch (data[EI_CLASS]) |
403 | { | 406 | { |
404 | case ELFCLASS32: | 407 | case ELFCLASS32: |
405 | if (size < sizeof (Elf32_Ehdr) + EI_NIDENT) | 408 | if (size < sizeof (Elf32_Ehdr) + EI_NIDENT) |
406 | return -1; | ||
407 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], | ||
408 | ELF_HEADER_SPECS[getByteorder (data[EI_DATA])], | ||
409 | ELF_HEADER_FIELDS (ehdr)); | ||
410 | if (ehdr->e_shoff + ehdr->e_shentsize * ehdr->e_shnum > size) | ||
411 | return -1; /* invalid offsets... */ | ||
412 | if (ehdr->e_shentsize < ELF_SECTION_SIZE) | ||
413 | return -1; /* huh? */ | ||
414 | if (ehdr->e_phoff + ehdr->e_phensize * ehdr->e_phnum > size) | ||
415 | return -1; | ||
416 | return 0; | ||
417 | case ELFCLASS64: | ||
418 | if (size < sizeof (Elf64_Ehdr) + EI_NIDENT) | ||
419 | return -1; | ||
420 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], | ||
421 | ELF64_HEADER_SPECS[getByteorder (data[EI_DATA])], | ||
422 | ELF64_HEADER_FIELDS (ehdr64)); | ||
423 | if (ehdr64->e_shoff + ((uint32_t) ehdr64->e_shentsize * ehdr64->e_shnum) > size) | ||
424 | return -1; /* invalid offsets... */ | ||
425 | if (ehdr64->e_phoff + ((uint32_t) ehdr64->e_phensize * ehdr64->e_phnum) > size) | ||
426 | return -1; | ||
427 | return 1; | ||
428 | default: | ||
429 | return -1; | 409 | return -1; |
430 | } | 410 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], |
411 | ELF_HEADER_SPECS[getByteorder (data[EI_DATA])], | ||
412 | ELF_HEADER_FIELDS (ehdr)); | ||
413 | if (ehdr->e_shoff + ehdr->e_shentsize * ehdr->e_shnum > size) | ||
414 | return -1; /* invalid offsets... */ | ||
415 | if (ehdr->e_shentsize < ELF_SECTION_SIZE) | ||
416 | return -1; /* huh? */ | ||
417 | if (ehdr->e_phoff + ehdr->e_phensize * ehdr->e_phnum > size) | ||
418 | return -1; | ||
419 | return 0; | ||
420 | case ELFCLASS64: | ||
421 | if (size < sizeof (Elf64_Ehdr) + EI_NIDENT) | ||
422 | return -1; | ||
423 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], | ||
424 | ELF64_HEADER_SPECS[getByteorder ( | ||
425 | data[EI_DATA])], | ||
426 | ELF64_HEADER_FIELDS (ehdr64)); | ||
427 | if (ehdr64->e_shoff + ((uint32_t) ehdr64->e_shentsize * ehdr64->e_shnum) > | ||
428 | size) | ||
429 | return -1; /* invalid offsets... */ | ||
430 | if (ehdr64->e_phoff + ((uint32_t) ehdr64->e_phensize * ehdr64->e_phnum) > | ||
431 | size) | ||
432 | return -1; | ||
433 | return 1; | ||
434 | default: | ||
435 | return -1; | ||
436 | } | ||
431 | } | 437 | } |
432 | 438 | ||
439 | |||
433 | /** | 440 | /** |
434 | * @return the string (offset into data, do NOT free), NULL on error | 441 | * @return the string (offset into data, do NOT free), NULL on error |
435 | */ | 442 | */ |
436 | static const char * | 443 | static const char * |
437 | readStringTable (const char *data, | 444 | readStringTable (const char *data, |
438 | size_t size, | 445 | size_t size, |
439 | Elf32_Ehdr * ehdr, | 446 | Elf32_Ehdr *ehdr, |
440 | Elf32_Half strTableOffset, Elf32_Word sh_name) | 447 | Elf32_Half strTableOffset, Elf32_Word sh_name) |
441 | { | 448 | { |
442 | Elf32_Shdr shrd; | 449 | Elf32_Shdr shrd; |
@@ -450,15 +457,19 @@ readStringTable (const char *data, | |||
450 | return &data[shrd.sh_offset + sh_name]; | 457 | return &data[shrd.sh_offset + sh_name]; |
451 | } | 458 | } |
452 | 459 | ||
453 | #define ADD(s, type) do { if (0!=proc(proc_cls, "elf", type, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) | 460 | |
461 | #define ADD(s, type) do { if (0!=proc (proc_cls, "elf", type, \ | ||
462 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", \ | ||
463 | s, strlen (s) + 1)) return 1; \ | ||
464 | } while (0) | ||
454 | 465 | ||
455 | /* application/x-executable, ELF */ | 466 | /* application/x-executable, ELF */ |
456 | int | 467 | int |
457 | EXTRACTOR_elf_extract (const char *data, | 468 | EXTRACTOR_elf_extract (const char *data, |
458 | size_t size, | 469 | size_t size, |
459 | EXTRACTOR_MetaDataProcessor proc, | 470 | EXTRACTOR_MetaDataProcessor proc, |
460 | void *proc_cls, | 471 | void *proc_cls, |
461 | const char *options) | 472 | const char *options) |
462 | { | 473 | { |
463 | Elf32_Ehdr ehdr; | 474 | Elf32_Ehdr ehdr; |
464 | Elf32_Half idx; | 475 | Elf32_Half idx; |
@@ -470,186 +481,186 @@ EXTRACTOR_elf_extract (const char *data, | |||
470 | return 0; | 481 | return 0; |
471 | ADD ("application/x-executable", EXTRACTOR_METATYPE_MIMETYPE); | 482 | ADD ("application/x-executable", EXTRACTOR_METATYPE_MIMETYPE); |
472 | switch ( ((unsigned char*) data)[EI_OSABI]) | 483 | switch ( ((unsigned char*) data)[EI_OSABI]) |
473 | { | 484 | { |
474 | case ELFOSABI_LINUX: | 485 | case ELFOSABI_LINUX: |
475 | ADD ("Linux", EXTRACTOR_METATYPE_TARGET_OS); | 486 | ADD ("Linux", EXTRACTOR_METATYPE_TARGET_OS); |
476 | break; | 487 | break; |
477 | case ELFOSABI_FREEBSD: | 488 | case ELFOSABI_FREEBSD: |
478 | ADD ("FreeBSD", EXTRACTOR_METATYPE_TARGET_OS); | 489 | ADD ("FreeBSD", EXTRACTOR_METATYPE_TARGET_OS); |
479 | break; | 490 | break; |
480 | case ELFOSABI_NETBSD: | 491 | case ELFOSABI_NETBSD: |
481 | ADD ("NetBSD", EXTRACTOR_METATYPE_TARGET_OS); | 492 | ADD ("NetBSD", EXTRACTOR_METATYPE_TARGET_OS); |
482 | break; | 493 | break; |
483 | case ELFOSABI_OPENBSD: | 494 | case ELFOSABI_OPENBSD: |
484 | ADD ("OpenBSD", EXTRACTOR_METATYPE_TARGET_OS); | 495 | ADD ("OpenBSD", EXTRACTOR_METATYPE_TARGET_OS); |
485 | break; | 496 | break; |
486 | case ELFOSABI_IRIX: | 497 | case ELFOSABI_IRIX: |
487 | ADD ("IRIX", EXTRACTOR_METATYPE_TARGET_OS); | 498 | ADD ("IRIX", EXTRACTOR_METATYPE_TARGET_OS); |
488 | break; | 499 | break; |
489 | default: | 500 | default: |
490 | break; | 501 | break; |
491 | } | 502 | } |
492 | switch ( (ret == 0) ? ehdr.e_type : ehdr64.e_type) | 503 | switch ( (ret == 0) ? ehdr.e_type : ehdr64.e_type) |
493 | { | 504 | { |
494 | case ET_REL: | 505 | case ET_REL: |
495 | ADD ("Relocatable file", EXTRACTOR_METATYPE_RESOURCE_TYPE); | 506 | ADD ("Relocatable file", EXTRACTOR_METATYPE_RESOURCE_TYPE); |
496 | break; | 507 | break; |
497 | case ET_EXEC: | 508 | case ET_EXEC: |
498 | ADD ("Executable file", EXTRACTOR_METATYPE_RESOURCE_TYPE); | 509 | ADD ("Executable file", EXTRACTOR_METATYPE_RESOURCE_TYPE); |
499 | break; | 510 | break; |
500 | case ET_DYN: | 511 | case ET_DYN: |
501 | ADD ("Shared object file", EXTRACTOR_METATYPE_RESOURCE_TYPE); | 512 | ADD ("Shared object file", EXTRACTOR_METATYPE_RESOURCE_TYPE); |
502 | break; | 513 | break; |
503 | case ET_CORE: | 514 | case ET_CORE: |
504 | ADD ("Core file", EXTRACTOR_METATYPE_RESOURCE_TYPE); | 515 | ADD ("Core file", EXTRACTOR_METATYPE_RESOURCE_TYPE); |
505 | break; | 516 | break; |
506 | default: | 517 | default: |
507 | break; /* unknown */ | 518 | break; /* unknown */ |
508 | } | 519 | } |
509 | switch ( (ret == 0) ? ehdr.e_machine : ehdr64.e_machine) | 520 | switch ( (ret == 0) ? ehdr.e_machine : ehdr64.e_machine) |
510 | { | 521 | { |
511 | case EM_M32: | 522 | case EM_M32: |
512 | ADD ("M32", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 523 | ADD ("M32", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
513 | break; | 524 | break; |
514 | case EM_386: | 525 | case EM_386: |
515 | ADD ("i386", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 526 | ADD ("i386", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
516 | break; | 527 | break; |
517 | case EM_68K: | 528 | case EM_68K: |
518 | ADD ("68K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 529 | ADD ("68K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
519 | break; | 530 | break; |
520 | case EM_88K: | 531 | case EM_88K: |
521 | ADD ("88K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 532 | ADD ("88K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
522 | break; | 533 | break; |
523 | case EM_SPARC: | 534 | case EM_SPARC: |
524 | ADD ("Sparc", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 535 | ADD ("Sparc", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
525 | break; | 536 | break; |
526 | case EM_860: | 537 | case EM_860: |
527 | ADD ("960", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 538 | ADD ("960", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
528 | break; | 539 | break; |
529 | case EM_MIPS: | 540 | case EM_MIPS: |
530 | ADD ("MIPS", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 541 | ADD ("MIPS", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
531 | break; | 542 | break; |
532 | case EM_PPC: | 543 | case EM_PPC: |
533 | ADD ("PPC", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 544 | ADD ("PPC", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
534 | break; | 545 | break; |
535 | case EM_PPC64: | 546 | case EM_PPC64: |
536 | ADD ("PPC64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 547 | ADD ("PPC64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
537 | break; | 548 | break; |
538 | case EM_S390: | 549 | case EM_S390: |
539 | ADD ("S390", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 550 | ADD ("S390", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
540 | break; | 551 | break; |
541 | case EM_ARM: | 552 | case EM_ARM: |
542 | ADD ("ARM", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 553 | ADD ("ARM", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
543 | break; | 554 | break; |
544 | case EM_ALPHA: | 555 | case EM_ALPHA: |
545 | ADD ("ALPHA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 556 | ADD ("ALPHA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
546 | break; | 557 | break; |
547 | case EM_IA_64: | 558 | case EM_IA_64: |
548 | ADD ("IA-64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 559 | ADD ("IA-64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
549 | break; | 560 | break; |
550 | case EM_X86_64: | 561 | case EM_X86_64: |
551 | ADD ("x86_64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 562 | ADD ("x86_64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
552 | break; | 563 | break; |
553 | case EM_CUDA: | 564 | case EM_CUDA: |
554 | ADD ("NVIDIA CUDA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 565 | ADD ("NVIDIA CUDA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); |
555 | break; | 566 | break; |
556 | default: | 567 | default: |
557 | break; /* oops */ | 568 | break; /* oops */ |
558 | } | 569 | } |
559 | 570 | ||
560 | if (ret != 0) | 571 | if (ret != 0) |
561 | return 0; /* FIXME: full support for 64-bit ELF... */ | 572 | return 0; /* FIXME: full support for 64-bit ELF... */ |
562 | for (idx = 0; idx < ehdr.e_phnum; idx++) | 573 | for (idx = 0; idx < ehdr.e_phnum; idx++) |
563 | { | 574 | { |
564 | Elf32_Phdr phdr; | 575 | Elf32_Phdr phdr; |
565 | 576 | ||
566 | if (0 != getProgramHdr (data, size, &ehdr, idx, &phdr)) | 577 | if (0 != getProgramHdr (data, size, &ehdr, idx, &phdr)) |
578 | return 0; | ||
579 | if (phdr.p_type == PT_DYNAMIC) | ||
580 | { | ||
581 | unsigned int dc = phdr.p_filesz / ELF_DYN_SIZE; | ||
582 | unsigned int id; | ||
583 | Elf32_Addr stringPtr; | ||
584 | Elf32_Half stringIdx; | ||
585 | Elf32_Half six; | ||
586 | |||
587 | stringPtr = 0; | ||
588 | |||
589 | for (id = 0; id < dc; id++) | ||
590 | { | ||
591 | Elf32_Dyn dyn; | ||
592 | if (0 != getDynTag (data, | ||
593 | size, | ||
594 | &ehdr, | ||
595 | phdr.p_offset, phdr.p_filesz, id, &dyn)) | ||
596 | return 0; | ||
597 | if (DT_STRTAB == dyn.d_tag) | ||
598 | { | ||
599 | stringPtr = dyn.d_un.d_ptr; | ||
600 | break; | ||
601 | } | ||
602 | } | ||
603 | if (stringPtr == 0) | ||
567 | return 0; | 604 | return 0; |
568 | if (phdr.p_type == PT_DYNAMIC) | 605 | for (six = 0; six < ehdr.e_shnum; six++) |
606 | { | ||
607 | Elf32_Shdr sec; | ||
608 | if (-1 == getSectionHdr (data, size, &ehdr, six, &sec)) | ||
609 | return 0; | ||
610 | if ((sec.sh_addr == stringPtr) && (sec.sh_type == SHT_STRTAB)) | ||
569 | { | 611 | { |
570 | unsigned int dc = phdr.p_filesz / ELF_DYN_SIZE; | 612 | stringIdx = six; |
571 | unsigned int id; | 613 | break; |
572 | Elf32_Addr stringPtr; | 614 | } |
573 | Elf32_Half stringIdx; | 615 | } |
574 | Elf32_Half six; | 616 | if (six == ehdr.e_shnum) |
575 | 617 | return 0; /* stringIdx not found */ | |
576 | stringPtr = 0; | 618 | |
577 | 619 | for (id = 0; id < dc; id++) | |
578 | for (id = 0; id < dc; id++) | 620 | { |
579 | { | 621 | Elf32_Dyn dyn; |
580 | Elf32_Dyn dyn; | 622 | if (0 != getDynTag (data, |
581 | if (0 != getDynTag (data, | 623 | size, |
582 | size, | 624 | &ehdr, |
583 | &ehdr, | 625 | phdr.p_offset, phdr.p_filesz, id, &dyn)) |
584 | phdr.p_offset, phdr.p_filesz, id, &dyn)) | 626 | return 0; |
585 | return 0; | 627 | switch (dyn.d_tag) |
586 | if (DT_STRTAB == dyn.d_tag) | 628 | { |
587 | { | 629 | case DT_RPATH: |
588 | stringPtr = dyn.d_un.d_ptr; | 630 | { |
589 | break; | 631 | const char *rpath; |
590 | } | 632 | |
591 | } | 633 | rpath = readStringTable (data, |
592 | if (stringPtr == 0) | 634 | size, |
593 | return 0; | 635 | &ehdr, |
594 | for (six = 0; six < ehdr.e_shnum; six++) | 636 | stringIdx, dyn.d_un.d_val); |
637 | /* "source" of the dependencies: path | ||
638 | to dynamic libraries */ | ||
639 | if (rpath != NULL) | ||
595 | { | 640 | { |
596 | Elf32_Shdr sec; | 641 | ADD (rpath, EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH); |
597 | if (-1 == getSectionHdr (data, size, &ehdr, six, &sec)) | ||
598 | return 0; | ||
599 | if ((sec.sh_addr == stringPtr) && (sec.sh_type == SHT_STRTAB)) | ||
600 | { | ||
601 | stringIdx = six; | ||
602 | break; | ||
603 | } | ||
604 | } | 642 | } |
605 | if (six == ehdr.e_shnum) | 643 | break; |
606 | return 0; /* stringIdx not found */ | 644 | } |
607 | 645 | case DT_NEEDED: | |
608 | for (id = 0; id < dc; id++) | 646 | { |
647 | const char *needed; | ||
648 | |||
649 | needed = readStringTable (data, | ||
650 | size, | ||
651 | &ehdr, | ||
652 | stringIdx, dyn.d_un.d_val); | ||
653 | if (needed != NULL) | ||
609 | { | 654 | { |
610 | Elf32_Dyn dyn; | 655 | ADD (needed, EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY); |
611 | if (0 != getDynTag (data, | ||
612 | size, | ||
613 | &ehdr, | ||
614 | phdr.p_offset, phdr.p_filesz, id, &dyn)) | ||
615 | return 0; | ||
616 | switch (dyn.d_tag) | ||
617 | { | ||
618 | case DT_RPATH: | ||
619 | { | ||
620 | const char *rpath; | ||
621 | |||
622 | rpath = readStringTable (data, | ||
623 | size, | ||
624 | &ehdr, | ||
625 | stringIdx, dyn.d_un.d_val); | ||
626 | /* "source" of the dependencies: path | ||
627 | to dynamic libraries */ | ||
628 | if (rpath != NULL) | ||
629 | { | ||
630 | ADD (rpath, EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH); | ||
631 | } | ||
632 | break; | ||
633 | } | ||
634 | case DT_NEEDED: | ||
635 | { | ||
636 | const char *needed; | ||
637 | |||
638 | needed = readStringTable (data, | ||
639 | size, | ||
640 | &ehdr, | ||
641 | stringIdx, dyn.d_un.d_val); | ||
642 | if (needed != NULL) | ||
643 | { | ||
644 | ADD (needed, EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY); | ||
645 | } | ||
646 | break; | ||
647 | } | ||
648 | } | ||
649 | } | 656 | } |
650 | 657 | break; | |
658 | } | ||
651 | } | 659 | } |
660 | } | ||
661 | |||
652 | } | 662 | } |
663 | } | ||
653 | 664 | ||
654 | return 0; | 665 | return 0; |
655 | } | 666 | } |
diff --git a/src/plugins/old/flv_extractor.c b/src/plugins/old/flv_extractor.c index f7d762d..2104d79 100644 --- a/src/plugins/old/flv_extractor.c +++ b/src/plugins/old/flv_extractor.c | |||
@@ -55,16 +55,18 @@ | |||
55 | #define ASTYPE_TYPEDOBJECT 0x10 | 55 | #define ASTYPE_TYPEDOBJECT 0x10 |
56 | #define ASTYPE_AMF3DATA 0x11 | 56 | #define ASTYPE_AMF3DATA 0x11 |
57 | 57 | ||
58 | typedef struct { | 58 | typedef struct |
59 | void * userdata; | 59 | { |
60 | void (*as_begin_callback)(unsigned char type, void * userdata); | 60 | void *userdata; |
61 | void (*as_key_callback)(char * key, void * userdata); | 61 | void (*as_begin_callback)(unsigned char type, void *userdata); |
62 | void (*as_end_callback)(unsigned char type, void * value, void * userdata); | 62 | void (*as_key_callback)(char *key, void *userdata); |
63 | void (*as_end_callback)(unsigned char type, void *value, void *userdata); | ||
63 | } AMFParserHandler; | 64 | } AMFParserHandler; |
64 | 65 | ||
65 | /* core datatypes */ | 66 | /* core datatypes */ |
66 | 67 | ||
67 | static uint32_t readInt32(const unsigned char **data) | 68 | static uint32_t |
69 | readInt32 (const unsigned char **data) | ||
68 | { | 70 | { |
69 | const unsigned char *ptr = *data; | 71 | const unsigned char *ptr = *data; |
70 | uint32_t val; | 72 | uint32_t val; |
@@ -75,7 +77,9 @@ static uint32_t readInt32(const unsigned char **data) | |||
75 | return val; | 77 | return val; |
76 | } | 78 | } |
77 | 79 | ||
78 | static uint32_t readInt24(const unsigned char **data) | 80 | |
81 | static uint32_t | ||
82 | readInt24 (const unsigned char **data) | ||
79 | { | 83 | { |
80 | const unsigned char *ptr = *data; | 84 | const unsigned char *ptr = *data; |
81 | uint32_t val; | 85 | uint32_t val; |
@@ -86,7 +90,9 @@ static uint32_t readInt24(const unsigned char **data) | |||
86 | return val; | 90 | return val; |
87 | } | 91 | } |
88 | 92 | ||
89 | static uint16_t readInt16(const unsigned char **data) | 93 | |
94 | static uint16_t | ||
95 | readInt16 (const unsigned char **data) | ||
90 | { | 96 | { |
91 | const unsigned char *ptr = *data; | 97 | const unsigned char *ptr = *data; |
92 | uint16_t val; | 98 | uint16_t val; |
@@ -97,14 +103,17 @@ static uint16_t readInt16(const unsigned char **data) | |||
97 | return val; | 103 | return val; |
98 | } | 104 | } |
99 | 105 | ||
100 | static double readDouble(const unsigned char **data) | 106 | |
107 | static double | ||
108 | readDouble (const unsigned char **data) | ||
101 | { | 109 | { |
102 | const unsigned char *ptr = *data; | 110 | const unsigned char *ptr = *data; |
103 | double val; | 111 | double val; |
104 | 112 | ||
105 | EXTRACTOR_common_floatformat_to_double(&EXTRACTOR_floatformat_ieee_double_big, | 113 | EXTRACTOR_common_floatformat_to_double ( |
106 | (const void *)ptr, | 114 | &EXTRACTOR_floatformat_ieee_double_big, |
107 | &val); | 115 | (const void *) ptr, |
116 | &val); | ||
108 | ptr += 8; | 117 | ptr += 8; |
109 | *data = ptr; | 118 | *data = ptr; |
110 | return val; | 119 | return val; |
@@ -113,9 +122,10 @@ static double readDouble(const unsigned char **data) | |||
113 | 122 | ||
114 | /* actionscript types */ | 123 | /* actionscript types */ |
115 | 124 | ||
116 | static int readASNumber(const unsigned char **data, | 125 | static int |
117 | size_t *len, | 126 | readASNumber (const unsigned char **data, |
118 | double *retval) | 127 | size_t *len, |
128 | double *retval) | ||
119 | { | 129 | { |
120 | const unsigned char *ptr = *data; | 130 | const unsigned char *ptr = *data; |
121 | double val; | 131 | double val; |
@@ -123,7 +133,7 @@ static int readASNumber(const unsigned char **data, | |||
123 | if (*len < 8) | 133 | if (*len < 8) |
124 | return -1; | 134 | return -1; |
125 | 135 | ||
126 | val = readDouble(&ptr); | 136 | val = readDouble (&ptr); |
127 | *len -= 8; | 137 | *len -= 8; |
128 | 138 | ||
129 | *retval = val; | 139 | *retval = val; |
@@ -131,9 +141,11 @@ static int readASNumber(const unsigned char **data, | |||
131 | return 0; | 141 | return 0; |
132 | } | 142 | } |
133 | 143 | ||
134 | static int readASBoolean(const unsigned char **data, | 144 | |
135 | size_t *len, | 145 | static int |
136 | int *retval) | 146 | readASBoolean (const unsigned char **data, |
147 | size_t *len, | ||
148 | int *retval) | ||
137 | { | 149 | { |
138 | const unsigned char *ptr = *data; | 150 | const unsigned char *ptr = *data; |
139 | int val; | 151 | int val; |
@@ -150,29 +162,33 @@ static int readASBoolean(const unsigned char **data, | |||
150 | return 0; | 162 | return 0; |
151 | } | 163 | } |
152 | 164 | ||
153 | static int readASDate(const unsigned char **data, | 165 | |
154 | size_t *len, | 166 | static int |
155 | double *millis, | 167 | readASDate (const unsigned char **data, |
156 | short *zone) | 168 | size_t *len, |
169 | double *millis, | ||
170 | short *zone) | ||
157 | { | 171 | { |
158 | const unsigned char *ptr = *data; | 172 | const unsigned char *ptr = *data; |
159 | 173 | ||
160 | if (*len < 10) | 174 | if (*len < 10) |
161 | return -1; | 175 | return -1; |
162 | 176 | ||
163 | *millis = readDouble(&ptr); | 177 | *millis = readDouble (&ptr); |
164 | *len -= 8; | 178 | *len -= 8; |
165 | 179 | ||
166 | *zone = readInt16(&ptr); | 180 | *zone = readInt16 (&ptr); |
167 | *len -= 2; | 181 | *len -= 2; |
168 | 182 | ||
169 | *data = ptr; | 183 | *data = ptr; |
170 | return 0; | 184 | return 0; |
171 | } | 185 | } |
172 | 186 | ||
173 | static int readASString(const unsigned char **data, | 187 | |
174 | size_t *len, | 188 | static int |
175 | char **retval) | 189 | readASString (const unsigned char **data, |
190 | size_t *len, | ||
191 | char **retval) | ||
176 | { | 192 | { |
177 | const unsigned char *ptr = *data; | 193 | const unsigned char *ptr = *data; |
178 | char *ret; | 194 | char *ret; |
@@ -181,15 +197,15 @@ static int readASString(const unsigned char **data, | |||
181 | if (*len < 2) | 197 | if (*len < 2) |
182 | return -1; | 198 | return -1; |
183 | 199 | ||
184 | slen = readInt16(&ptr); | 200 | slen = readInt16 (&ptr); |
185 | 201 | ||
186 | if (*len < (2 + slen)) | 202 | if (*len < (2 + slen)) |
187 | return -1; | 203 | return -1; |
188 | 204 | ||
189 | ret = malloc(slen+1); | 205 | ret = malloc (slen + 1); |
190 | if (ret == NULL) | 206 | if (ret == NULL) |
191 | return -1; | 207 | return -1; |
192 | memcpy(ret, ptr, slen); | 208 | memcpy (ret, ptr, slen); |
193 | ret[slen] = '\0'; | 209 | ret[slen] = '\0'; |
194 | ptr += slen; | 210 | ptr += slen; |
195 | *len -= (2 + slen); | 211 | *len -= (2 + slen); |
@@ -199,9 +215,11 @@ static int readASString(const unsigned char **data, | |||
199 | return 0; | 215 | return 0; |
200 | } | 216 | } |
201 | 217 | ||
202 | static int parse_amf(const unsigned char **data, | 218 | |
203 | size_t *len, | 219 | static int |
204 | AMFParserHandler *handler) | 220 | parse_amf (const unsigned char **data, |
221 | size_t *len, | ||
222 | AMFParserHandler *handler) | ||
205 | { | 223 | { |
206 | const unsigned char *ptr = *data; | 224 | const unsigned char *ptr = *data; |
207 | unsigned char astype; | 225 | unsigned char astype; |
@@ -210,45 +228,47 @@ static int parse_amf(const unsigned char **data, | |||
210 | ret = 0; | 228 | ret = 0; |
211 | astype = *ptr++; | 229 | astype = *ptr++; |
212 | (*(handler->as_begin_callback))(astype, handler->userdata); | 230 | (*(handler->as_begin_callback))(astype, handler->userdata); |
213 | switch (astype) { | 231 | switch (astype) |
214 | case ASTYPE_NUMBER: | 232 | { |
233 | case ASTYPE_NUMBER: | ||
215 | { | 234 | { |
216 | double val; | 235 | double val; |
217 | ret = readASNumber(&ptr, len, &val); | 236 | ret = readASNumber (&ptr, len, &val); |
218 | if (ret == 0) | 237 | if (ret == 0) |
219 | (*(handler->as_end_callback))(astype, | 238 | (*(handler->as_end_callback))(astype, |
220 | &val, | 239 | &val, |
221 | handler->userdata); | 240 | handler->userdata); |
222 | break; | 241 | break; |
223 | } | 242 | } |
224 | case ASTYPE_BOOLEAN: | 243 | case ASTYPE_BOOLEAN: |
225 | { | 244 | { |
226 | int val; | 245 | int val; |
227 | ret = readASBoolean(&ptr, len, &val); | 246 | ret = readASBoolean (&ptr, len, &val); |
228 | if (ret == 0) | 247 | if (ret == 0) |
229 | (*(handler->as_end_callback))(astype, | 248 | (*(handler->as_end_callback))(astype, |
230 | &val, | 249 | &val, |
231 | handler->userdata); | 250 | handler->userdata); |
232 | break; | 251 | break; |
233 | } | 252 | } |
234 | case ASTYPE_STRING: | 253 | case ASTYPE_STRING: |
235 | { | 254 | { |
236 | char *val; | 255 | char *val; |
237 | ret = readASString(&ptr, len, &val); | 256 | ret = readASString (&ptr, len, &val); |
238 | if (ret == 0) { | 257 | if (ret == 0) |
258 | { | ||
239 | (*(handler->as_end_callback))(astype, | 259 | (*(handler->as_end_callback))(astype, |
240 | val, | 260 | val, |
241 | handler->userdata); | 261 | handler->userdata); |
242 | free(val); | 262 | free (val); |
243 | } | 263 | } |
244 | break; | 264 | break; |
245 | } | 265 | } |
246 | case ASTYPE_DATE: | 266 | case ASTYPE_DATE: |
247 | { | 267 | { |
248 | void *tmp[2]; | 268 | void *tmp[2]; |
249 | double millis; | 269 | double millis; |
250 | short tz; | 270 | short tz; |
251 | ret = readASDate(&ptr, len, &millis, &tz); | 271 | ret = readASDate (&ptr, len, &millis, &tz); |
252 | tmp[0] = &millis; | 272 | tmp[0] = &millis; |
253 | tmp[1] = &tz; | 273 | tmp[1] = &tz; |
254 | if (ret == 0) | 274 | if (ret == 0) |
@@ -257,53 +277,56 @@ static int parse_amf(const unsigned char **data, | |||
257 | handler->userdata); | 277 | handler->userdata); |
258 | break; | 278 | break; |
259 | } | 279 | } |
260 | case ASTYPE_NULL: | 280 | case ASTYPE_NULL: |
261 | case ASTYPE_UNDEFINED: | 281 | case ASTYPE_UNDEFINED: |
262 | case ASTYPE_UNSUPPORTED: | 282 | case ASTYPE_UNSUPPORTED: |
263 | case ASTYPE_ENDOFOBJECT: | 283 | case ASTYPE_ENDOFOBJECT: |
264 | (*(handler->as_end_callback))(astype, NULL, handler->userdata); | 284 | (*(handler->as_end_callback))(astype, NULL, handler->userdata); |
265 | break; | 285 | break; |
266 | case ASTYPE_ARRAY: | 286 | case ASTYPE_ARRAY: |
267 | { | 287 | { |
268 | long i, alen; | 288 | long i, alen; |
269 | if (*len < 4) { | 289 | if (*len < 4) |
290 | { | ||
270 | ret = -1; | 291 | ret = -1; |
271 | break; | 292 | break; |
272 | } | 293 | } |
273 | alen = readInt32(&ptr); | 294 | alen = readInt32 (&ptr); |
274 | *len -= 4; | 295 | *len -= 4; |
275 | for (i = 0; i < alen; i++) { | 296 | for (i = 0; i < alen; i++) |
276 | ret = parse_amf(&ptr, len, handler); | 297 | { |
298 | ret = parse_amf (&ptr, len, handler); | ||
277 | if (ret == -1) | 299 | if (ret == -1) |
278 | break; | 300 | break; |
279 | } | 301 | } |
280 | (*(handler->as_end_callback))(ASTYPE_ARRAY, | 302 | (*(handler->as_end_callback))(ASTYPE_ARRAY, |
281 | NULL, | 303 | NULL, |
282 | handler->userdata); | 304 | handler->userdata); |
283 | break; | 305 | break; |
284 | } | 306 | } |
285 | case ASTYPE_OBJECT: | 307 | case ASTYPE_OBJECT: |
286 | { | 308 | { |
287 | char *key; | 309 | char *key; |
288 | unsigned char type; | 310 | unsigned char type; |
289 | 311 | ||
290 | ret = readASString(&ptr, len, &key); | 312 | ret = readASString (&ptr, len, &key); |
291 | if (ret == -1) | 313 | if (ret == -1) |
292 | break; | 314 | break; |
293 | (*(handler->as_key_callback))(key, | 315 | (*(handler->as_key_callback))(key, |
294 | handler->userdata); | 316 | handler->userdata); |
295 | free(key); | 317 | free (key); |
296 | type = *ptr; | 318 | type = *ptr; |
297 | while (type != ASTYPE_ENDOFOBJECT) { | 319 | while (type != ASTYPE_ENDOFOBJECT) |
298 | ret = parse_amf(&ptr, len, handler); | 320 | { |
321 | ret = parse_amf (&ptr, len, handler); | ||
299 | if (ret == -1) | 322 | if (ret == -1) |
300 | break; | 323 | break; |
301 | ret = readASString(&ptr, len, &key); | 324 | ret = readASString (&ptr, len, &key); |
302 | if (ret == -1) | 325 | if (ret == -1) |
303 | break; | 326 | break; |
304 | (*(handler->as_key_callback))(key, | 327 | (*(handler->as_key_callback))(key, |
305 | handler->userdata); | 328 | handler->userdata); |
306 | free(key); | 329 | free (key); |
307 | type = *ptr; | 330 | type = *ptr; |
308 | } | 331 | } |
309 | if (ret == 0) | 332 | if (ret == 0) |
@@ -312,34 +335,36 @@ static int parse_amf(const unsigned char **data, | |||
312 | handler->userdata); | 335 | handler->userdata); |
313 | break; | 336 | break; |
314 | } | 337 | } |
315 | case ASTYPE_MIXEDARRAY: | 338 | case ASTYPE_MIXEDARRAY: |
316 | { | 339 | { |
317 | char *key; | 340 | char *key; |
318 | unsigned char type; | 341 | unsigned char type; |
319 | 342 | ||
320 | if (*len < 4) { | 343 | if (*len < 4) |
344 | { | ||
321 | ret = -1; | 345 | ret = -1; |
322 | break; | 346 | break; |
323 | } | 347 | } |
324 | /* max_index */ readInt32(&ptr); | 348 | /* max_index */ readInt32 (&ptr); |
325 | *len -= 4; | 349 | *len -= 4; |
326 | ret = readASString(&ptr, len, &key); | 350 | ret = readASString (&ptr, len, &key); |
327 | if (ret == -1) | 351 | if (ret == -1) |
328 | break; | 352 | break; |
329 | (*(handler->as_key_callback))(key, | 353 | (*(handler->as_key_callback))(key, |
330 | handler->userdata); | 354 | handler->userdata); |
331 | free(key); | 355 | free (key); |
332 | type = *ptr; | 356 | type = *ptr; |
333 | while (type != ASTYPE_ENDOFOBJECT) { | 357 | while (type != ASTYPE_ENDOFOBJECT) |
334 | ret = parse_amf(&ptr, len, handler); | 358 | { |
359 | ret = parse_amf (&ptr, len, handler); | ||
335 | if (ret == -1) | 360 | if (ret == -1) |
336 | break; | 361 | break; |
337 | ret = readASString(&ptr, len, &key); | 362 | ret = readASString (&ptr, len, &key); |
338 | if (ret == -1) | 363 | if (ret == -1) |
339 | break; | 364 | break; |
340 | (*(handler->as_key_callback))(key, | 365 | (*(handler->as_key_callback))(key, |
341 | handler->userdata); | 366 | handler->userdata); |
342 | free(key); | 367 | free (key); |
343 | type = *ptr; | 368 | type = *ptr; |
344 | } | 369 | } |
345 | if (ret == 0) | 370 | if (ret == 0) |
@@ -348,21 +373,22 @@ static int parse_amf(const unsigned char **data, | |||
348 | handler->userdata); | 373 | handler->userdata); |
349 | break; | 374 | break; |
350 | } | 375 | } |
351 | default: | 376 | default: |
352 | ret = -1; | 377 | ret = -1; |
353 | (*(handler->as_end_callback))(astype, | 378 | (*(handler->as_end_callback))(astype, |
354 | NULL, | 379 | NULL, |
355 | handler->userdata); | 380 | handler->userdata); |
356 | #if DEBUG | 381 | #if DEBUG |
357 | printf("parse_amf: Unknown type %02x", astype); | 382 | printf ("parse_amf: Unknown type %02x", astype); |
358 | #endif | 383 | #endif |
359 | break; | 384 | break; |
360 | } | 385 | } |
361 | 386 | ||
362 | *data = ptr; | 387 | *data = ptr; |
363 | return ret; | 388 | return ret; |
364 | } | 389 | } |
365 | 390 | ||
391 | |||
366 | /* | 392 | /* |
367 | * FLV parser | 393 | * FLV parser |
368 | */ | 394 | */ |
@@ -379,8 +405,9 @@ flv_to_iso_date (double timeval, short timezone, | |||
379 | * shift epoch to proleptic times | 405 | * shift epoch to proleptic times |
380 | * to make subsequent modulo operations safer. | 406 | * to make subsequent modulo operations safer. |
381 | */ | 407 | */ |
382 | long long my_timeval = (timeval/1000) | 408 | long long my_timeval = (timeval / 1000) |
383 | + ((long long) ((1970 * 365) + 478) * (long long) 86400); | 409 | + ((long long) ((1970 * 365) + 478) * (long |
410 | long) 86400); | ||
384 | 411 | ||
385 | unsigned int seconds = (unsigned int) (my_timeval % 60); | 412 | unsigned int seconds = (unsigned int) (my_timeval % 60); |
386 | unsigned int minutes = (unsigned int) ((my_timeval / 60) % 60); | 413 | unsigned int minutes = (unsigned int) ((my_timeval / 60) % 60); |
@@ -396,7 +423,7 @@ flv_to_iso_date (double timeval, short timezone, | |||
396 | unsigned int days = (unsigned int) (my_timeval / (24 * 3600)); | 423 | unsigned int days = (unsigned int) (my_timeval / (24 * 3600)); |
397 | 424 | ||
398 | unsigned int days_in_month[] = | 425 | unsigned int days_in_month[] = |
399 | { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | 426 | { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
400 | unsigned int diff = 0; | 427 | unsigned int diff = 0; |
401 | 428 | ||
402 | if ((long long) 0 > my_timeval) | 429 | if ((long long) 0 > my_timeval) |
@@ -413,15 +440,15 @@ flv_to_iso_date (double timeval, short timezone, | |||
413 | */ | 440 | */ |
414 | diff = (days / ((365 * 100) + 24)); | 441 | diff = (days / ((365 * 100) + 24)); |
415 | if (4 <= diff) | 442 | if (4 <= diff) |
416 | { | 443 | { |
417 | year += 399; | 444 | year += 399; |
418 | days = 364; | 445 | days = 364; |
419 | } | 446 | } |
420 | else | 447 | else |
421 | { | 448 | { |
422 | year += (100 * diff); | 449 | year += (100 * diff); |
423 | days %= ((365 * 100) + 24); | 450 | days %= ((365 * 100) + 24); |
424 | } | 451 | } |
425 | 452 | ||
426 | /* | 453 | /* |
427 | * remaining leap years | 454 | * remaining leap years |
@@ -430,32 +457,32 @@ flv_to_iso_date (double timeval, short timezone, | |||
430 | days %= ((365 * 4) + 1); | 457 | days %= ((365 * 4) + 1); |
431 | 458 | ||
432 | while (1) | 459 | while (1) |
460 | { | ||
461 | if ((0 == (year % 400)) || ((0 == (year % 4)) && (0 != (year % 100)))) | ||
433 | { | 462 | { |
434 | if ((0 == (year % 400)) || ((0 == (year % 4)) && (0 != (year % 100)))) | 463 | if (366 > days) |
435 | { | 464 | { |
436 | if (366 > days) | 465 | break; |
437 | { | 466 | } |
438 | break; | ||
439 | } | ||
440 | else | ||
441 | { | ||
442 | days -= 366; | ||
443 | year++; | ||
444 | } | ||
445 | } | ||
446 | else | 467 | else |
447 | { | 468 | { |
448 | if (365 > days) | 469 | days -= 366; |
449 | { | 470 | year++; |
450 | break; | 471 | } |
451 | } | 472 | } |
452 | else | 473 | else |
453 | { | 474 | { |
454 | days -= 365; | 475 | if (365 > days) |
455 | year++; | 476 | { |
456 | } | 477 | break; |
457 | } | 478 | } |
479 | else | ||
480 | { | ||
481 | days -= 365; | ||
482 | year++; | ||
483 | } | ||
458 | } | 484 | } |
485 | } | ||
459 | 486 | ||
460 | if ((0 == (year % 400)) || ((0 == (year % 4)) && (0 != (year % 100)))) | 487 | if ((0 == (year % 400)) || ((0 == (year % 4)) && (0 != (year % 100)))) |
461 | days_in_month[1] = 29; | 488 | days_in_month[1] = 29; |
@@ -465,12 +492,12 @@ flv_to_iso_date (double timeval, short timezone, | |||
465 | 492 | ||
466 | zone_sign = 0; | 493 | zone_sign = 0; |
467 | if (timezone < 0) | 494 | if (timezone < 0) |
468 | { | 495 | { |
469 | zone_sign = -1; | 496 | zone_sign = -1; |
470 | timezone = -timezone; | 497 | timezone = -timezone; |
471 | } | 498 | } |
472 | zone_hours = timezone/60; | 499 | zone_hours = timezone / 60; |
473 | zone_minutes = timezone - zone_hours*60; | 500 | zone_minutes = timezone - zone_hours * 60; |
474 | 501 | ||
475 | retval = snprintf (rtime, rsize, "%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02u", | 502 | retval = snprintf (rtime, rsize, "%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02u", |
476 | year, month + 1, days + 1, hours, minutes, seconds, | 503 | year, month + 1, days + 1, hours, minutes, seconds, |
@@ -479,6 +506,7 @@ flv_to_iso_date (double timeval, short timezone, | |||
479 | return (retval < rsize) ? 0 : EOVERFLOW; | 506 | return (retval < rsize) ? 0 : EOVERFLOW; |
480 | } | 507 | } |
481 | 508 | ||
509 | |||
482 | typedef struct | 510 | typedef struct |
483 | { | 511 | { |
484 | char signature[3]; | 512 | char signature[3]; |
@@ -503,20 +531,21 @@ typedef struct | |||
503 | 531 | ||
504 | #define FLV_TAG_HEADER_SIZE 11 | 532 | #define FLV_TAG_HEADER_SIZE 11 |
505 | 533 | ||
506 | static int readFLVHeader(const unsigned char **data, | 534 | static int |
507 | const unsigned char *end, | 535 | readFLVHeader (const unsigned char **data, |
508 | FLVHeader *hdr) | 536 | const unsigned char *end, |
537 | FLVHeader *hdr) | ||
509 | { | 538 | { |
510 | const unsigned char *ptr = *data; | 539 | const unsigned char *ptr = *data; |
511 | 540 | ||
512 | if ((ptr + FLV_HEADER_SIZE) > end) | 541 | if ((ptr + FLV_HEADER_SIZE) > end) |
513 | return -1; | 542 | return -1; |
514 | 543 | ||
515 | memcpy(hdr->signature, ptr, 3); | 544 | memcpy (hdr->signature, ptr, 3); |
516 | ptr += 3; | 545 | ptr += 3; |
517 | hdr->version = *ptr++; | 546 | hdr->version = *ptr++; |
518 | hdr->flags = *ptr++; | 547 | hdr->flags = *ptr++; |
519 | hdr->offset = readInt32(&ptr); | 548 | hdr->offset = readInt32 (&ptr); |
520 | if (hdr->offset != FLV_HEADER_SIZE) | 549 | if (hdr->offset != FLV_HEADER_SIZE) |
521 | return -1; | 550 | return -1; |
522 | 551 | ||
@@ -524,24 +553,28 @@ static int readFLVHeader(const unsigned char **data, | |||
524 | return 0; | 553 | return 0; |
525 | } | 554 | } |
526 | 555 | ||
527 | static int readPreviousTagSize(const unsigned char **data, | 556 | |
528 | const unsigned char *end, | 557 | static int |
529 | unsigned long *prev_size) | 558 | readPreviousTagSize (const unsigned char **data, |
559 | const unsigned char *end, | ||
560 | unsigned long *prev_size) | ||
530 | { | 561 | { |
531 | const unsigned char *ptr = *data; | 562 | const unsigned char *ptr = *data; |
532 | 563 | ||
533 | if ((ptr + 4) > end) | 564 | if ((ptr + 4) > end) |
534 | return -1; | 565 | return -1; |
535 | 566 | ||
536 | *prev_size = readInt32(&ptr); | 567 | *prev_size = readInt32 (&ptr); |
537 | 568 | ||
538 | *data = ptr; | 569 | *data = ptr; |
539 | return 0; | 570 | return 0; |
540 | } | 571 | } |
541 | 572 | ||
542 | static int readFLVTagHeader(const unsigned char **data, | 573 | |
543 | const unsigned char *end, | 574 | static int |
544 | FLVTagHeader *hdr) | 575 | readFLVTagHeader (const unsigned char **data, |
576 | const unsigned char *end, | ||
577 | FLVTagHeader *hdr) | ||
545 | { | 578 | { |
546 | const unsigned char *ptr = *data; | 579 | const unsigned char *ptr = *data; |
547 | 580 | ||
@@ -549,15 +582,17 @@ static int readFLVTagHeader(const unsigned char **data, | |||
549 | return -1; | 582 | return -1; |
550 | 583 | ||
551 | hdr->type = *ptr++; | 584 | hdr->type = *ptr++; |
552 | hdr->bodyLength = readInt24(&ptr); | 585 | hdr->bodyLength = readInt24 (&ptr); |
553 | hdr->timestamp = readInt32(&ptr); | 586 | hdr->timestamp = readInt32 (&ptr); |
554 | hdr->streamId = readInt24(&ptr); | 587 | hdr->streamId = readInt24 (&ptr); |
555 | 588 | ||
556 | *data = ptr; | 589 | *data = ptr; |
557 | return 0; | 590 | return 0; |
558 | } | 591 | } |
559 | 592 | ||
560 | typedef struct { | 593 | |
594 | typedef struct | ||
595 | { | ||
561 | int videoCodec; | 596 | int videoCodec; |
562 | char *videoCodecStr; | 597 | char *videoCodecStr; |
563 | int videoWidth; | 598 | int videoWidth; |
@@ -573,7 +608,8 @@ typedef struct { | |||
573 | int audioRate; | 608 | int audioRate; |
574 | } FLVStreamInfo; | 609 | } FLVStreamInfo; |
575 | 610 | ||
576 | typedef enum { | 611 | typedef enum |
612 | { | ||
577 | FLV_NONE = 0, | 613 | FLV_NONE = 0, |
578 | FLV_WIDTH, | 614 | FLV_WIDTH, |
579 | FLV_HEIGHT, | 615 | FLV_HEIGHT, |
@@ -586,7 +622,8 @@ typedef enum { | |||
586 | FLV_ACODECID | 622 | FLV_ACODECID |
587 | } FLVStreamAttribute; | 623 | } FLVStreamAttribute; |
588 | 624 | ||
589 | typedef struct { | 625 | typedef struct |
626 | { | ||
590 | const char *key; | 627 | const char *key; |
591 | FLVStreamAttribute attribute; | 628 | FLVStreamAttribute attribute; |
592 | } MetaKeyToStreamAttribute; | 629 | } MetaKeyToStreamAttribute; |
@@ -605,7 +642,8 @@ static MetaKeyToStreamAttribute key_to_attribute_map[] = { | |||
605 | { NULL, FLV_NONE } | 642 | { NULL, FLV_NONE } |
606 | }; | 643 | }; |
607 | 644 | ||
608 | typedef struct { | 645 | typedef struct |
646 | { | ||
609 | const char *key; | 647 | const char *key; |
610 | enum EXTRACTOR_MetaType type; | 648 | enum EXTRACTOR_MetaType type; |
611 | } MetaKeyToExtractorItem; | 649 | } MetaKeyToExtractorItem; |
@@ -619,7 +657,8 @@ static MetaKeyToExtractorItem key_to_extractor_map[] = { | |||
619 | { NULL, EXTRACTOR_METATYPE_RESERVED } | 657 | { NULL, EXTRACTOR_METATYPE_RESERVED } |
620 | }; | 658 | }; |
621 | 659 | ||
622 | typedef struct { | 660 | typedef struct |
661 | { | ||
623 | int onMetaData; | 662 | int onMetaData; |
624 | int parsingDepth; | 663 | int parsingDepth; |
625 | int ret; | 664 | int ret; |
@@ -632,22 +671,25 @@ typedef struct { | |||
632 | FLVStreamInfo *streamInfo; | 671 | FLVStreamInfo *streamInfo; |
633 | } FLVMetaParserState; | 672 | } FLVMetaParserState; |
634 | 673 | ||
635 | static void handleASBegin(unsigned char type, void * userdata) | 674 | static void |
675 | handleASBegin (unsigned char type, void *userdata) | ||
636 | { | 676 | { |
637 | FLVMetaParserState *state = (FLVMetaParserState *)userdata; | 677 | FLVMetaParserState *state = (FLVMetaParserState *) userdata; |
638 | 678 | ||
639 | if (state->onMetaData && state->parsingDepth == 0 && | 679 | if (state->onMetaData && (state->parsingDepth == 0) && |
640 | type != ASTYPE_MIXEDARRAY) | 680 | (type != ASTYPE_MIXEDARRAY) ) |
641 | state->onMetaData = 0; | 681 | state->onMetaData = 0; |
642 | 682 | ||
643 | if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || | 683 | if ((type == ASTYPE_ARRAY) || (type == ASTYPE_MIXEDARRAY) || |
644 | type == ASTYPE_OBJECT) | 684 | (type == ASTYPE_OBJECT) ) |
645 | state->parsingDepth++; | 685 | state->parsingDepth++; |
646 | } | 686 | } |
647 | 687 | ||
648 | static void handleASKey(char * key, void * userdata) | 688 | |
689 | static void | ||
690 | handleASKey (char *key, void *userdata) | ||
649 | { | 691 | { |
650 | FLVMetaParserState *state = (FLVMetaParserState *)userdata; | 692 | FLVMetaParserState *state = (FLVMetaParserState *) userdata; |
651 | int i; | 693 | int i; |
652 | 694 | ||
653 | if (key == NULL) | 695 | if (key == NULL) |
@@ -655,26 +697,29 @@ static void handleASKey(char * key, void * userdata) | |||
655 | 697 | ||
656 | i = 0; | 698 | i = 0; |
657 | while ((key_to_extractor_map[i].key != NULL) && | 699 | while ((key_to_extractor_map[i].key != NULL) && |
658 | (strcasecmp(key, key_to_extractor_map[i].key) != 0)) | 700 | (strcasecmp (key, key_to_extractor_map[i].key) != 0)) |
659 | i++; | 701 | i++; |
660 | state->currentKeyType = key_to_extractor_map[i].type; | 702 | state->currentKeyType = key_to_extractor_map[i].type; |
661 | 703 | ||
662 | i = 0; | 704 | i = 0; |
663 | while ((key_to_attribute_map[i].key != NULL) && | 705 | while ((key_to_attribute_map[i].key != NULL) && |
664 | (strcasecmp(key, key_to_attribute_map[i].key) != 0)) | 706 | (strcasecmp (key, key_to_attribute_map[i].key) != 0)) |
665 | i++; | 707 | i++; |
666 | state->currentAttribute = key_to_attribute_map[i].attribute; | 708 | state->currentAttribute = key_to_attribute_map[i].attribute; |
667 | } | 709 | } |
668 | 710 | ||
669 | static void handleASEnd(unsigned char type, void * value, void * userdata) | 711 | |
712 | static void | ||
713 | handleASEnd (unsigned char type, void *value, void *userdata) | ||
670 | { | 714 | { |
671 | FLVMetaParserState *state = (FLVMetaParserState *)userdata; | 715 | FLVMetaParserState *state = (FLVMetaParserState *) userdata; |
672 | const char *s; | 716 | const char *s; |
673 | char tmpstr[30]; | 717 | char tmpstr[30]; |
674 | 718 | ||
675 | if ((state->parsingDepth == 0) && (type == ASTYPE_STRING)) { | 719 | if ((state->parsingDepth == 0) && (type == ASTYPE_STRING)) |
676 | s = (const char *)value; | 720 | { |
677 | if (!strcmp(s, "onMetaData")) | 721 | s = (const char *) value; |
722 | if (! strcmp (s, "onMetaData")) | ||
678 | state->onMetaData = 1; | 723 | state->onMetaData = 1; |
679 | } | 724 | } |
680 | 725 | ||
@@ -686,50 +731,53 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
686 | (state->currentAttribute != FLV_NONE) && | 731 | (state->currentAttribute != FLV_NONE) && |
687 | (type == ASTYPE_NUMBER)) | 732 | (type == ASTYPE_NUMBER)) |
688 | { | 733 | { |
689 | double n = *((double *)value); | 734 | double n = *((double *) value); |
690 | switch (state->currentAttribute) { | 735 | switch (state->currentAttribute) |
691 | case FLV_NONE: /* make gcc happy */ | 736 | { |
692 | break; | 737 | case FLV_NONE: /* make gcc happy */ |
693 | case FLV_STEREO: | 738 | break; |
694 | break; | 739 | case FLV_STEREO: |
695 | case FLV_ACHANNELS: | 740 | break; |
696 | state->streamInfo->audioChannels = n; | 741 | case FLV_ACHANNELS: |
697 | break; | 742 | state->streamInfo->audioChannels = n; |
698 | case FLV_WIDTH: | 743 | break; |
699 | if (state->streamInfo->videoWidth == -1) | 744 | case FLV_WIDTH: |
700 | state->streamInfo->videoWidth = n; | 745 | if (state->streamInfo->videoWidth == -1) |
701 | break; | 746 | state->streamInfo->videoWidth = n; |
702 | case FLV_HEIGHT: | 747 | break; |
703 | if (state->streamInfo->videoHeight == -1) | 748 | case FLV_HEIGHT: |
704 | state->streamInfo->videoHeight = n; | 749 | if (state->streamInfo->videoHeight == -1) |
705 | break; | 750 | state->streamInfo->videoHeight = n; |
706 | case FLV_FRAMERATE: | 751 | break; |
707 | state->streamInfo->videoFrameRate = n; | 752 | case FLV_FRAMERATE: |
708 | break; | 753 | state->streamInfo->videoFrameRate = n; |
709 | case FLV_VDATARATE: | 754 | break; |
710 | state->streamInfo->videoDataRate = n; | 755 | case FLV_VDATARATE: |
711 | break; | 756 | state->streamInfo->videoDataRate = n; |
712 | case FLV_ADATARATE: | 757 | break; |
713 | state->streamInfo->audioDataRate = n; | 758 | case FLV_ADATARATE: |
714 | break; | 759 | state->streamInfo->audioDataRate = n; |
715 | case FLV_VCODECID: | 760 | break; |
716 | if (state->streamInfo->videoCodec == -1) | 761 | case FLV_VCODECID: |
717 | state->streamInfo->videoCodec = n; | 762 | if (state->streamInfo->videoCodec == -1) |
718 | /* prefer codec ids to fourcc codes */ | 763 | state->streamInfo->videoCodec = n; |
719 | if (state->streamInfo->videoCodecStr != NULL) { | 764 | /* prefer codec ids to fourcc codes */ |
720 | free(state->streamInfo->videoCodecStr); | 765 | if (state->streamInfo->videoCodecStr != NULL) |
721 | state->streamInfo->videoCodecStr = NULL; | 766 | { |
722 | } | 767 | free (state->streamInfo->videoCodecStr); |
723 | break; | 768 | state->streamInfo->videoCodecStr = NULL; |
724 | case FLV_ACODECID: | 769 | } |
725 | if (state->streamInfo->audioCodec == -1) | 770 | break; |
726 | state->streamInfo->audioCodec = n; | 771 | case FLV_ACODECID: |
727 | /* prefer codec ids to fourcc codes */ | 772 | if (state->streamInfo->audioCodec == -1) |
728 | if (state->streamInfo->audioCodecStr != NULL) { | 773 | state->streamInfo->audioCodec = n; |
729 | free(state->streamInfo->audioCodecStr); | 774 | /* prefer codec ids to fourcc codes */ |
730 | state->streamInfo->audioCodecStr = NULL; | 775 | if (state->streamInfo->audioCodecStr != NULL) |
731 | } | 776 | { |
732 | break; | 777 | free (state->streamInfo->audioCodecStr); |
778 | state->streamInfo->audioCodecStr = NULL; | ||
779 | } | ||
780 | break; | ||
733 | } | 781 | } |
734 | } | 782 | } |
735 | 783 | ||
@@ -738,20 +786,21 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
738 | (state->currentAttribute != FLV_NONE) && | 786 | (state->currentAttribute != FLV_NONE) && |
739 | (type == ASTYPE_STRING)) | 787 | (type == ASTYPE_STRING)) |
740 | { | 788 | { |
741 | s = (const char *)value; | 789 | s = (const char *) value; |
742 | switch (state->currentAttribute) { | 790 | switch (state->currentAttribute) |
743 | case FLV_VCODECID: | 791 | { |
744 | if (s != NULL && state->streamInfo->videoCodecStr == NULL && | 792 | case FLV_VCODECID: |
745 | state->streamInfo->videoCodec == -1) | 793 | if ((s != NULL) && (state->streamInfo->videoCodecStr == NULL) && |
746 | state->streamInfo->videoCodecStr = strdup(s); | 794 | (state->streamInfo->videoCodec == -1) ) |
747 | break; | 795 | state->streamInfo->videoCodecStr = strdup (s); |
748 | case FLV_ACODECID: | 796 | break; |
749 | if (s != NULL && state->streamInfo->audioCodecStr == NULL && | 797 | case FLV_ACODECID: |
750 | state->streamInfo->audioCodec == -1) | 798 | if ((s != NULL) && (state->streamInfo->audioCodecStr == NULL) && |
751 | state->streamInfo->audioCodecStr = strdup(s); | 799 | (state->streamInfo->audioCodec == -1) ) |
752 | break; | 800 | state->streamInfo->audioCodecStr = strdup (s); |
753 | default: | 801 | break; |
754 | break; | 802 | default: |
803 | break; | ||
755 | } | 804 | } |
756 | } | 805 | } |
757 | 806 | ||
@@ -759,7 +808,7 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
759 | (state->currentAttribute == FLV_STEREO) && | 808 | (state->currentAttribute == FLV_STEREO) && |
760 | (type == ASTYPE_BOOLEAN)) | 809 | (type == ASTYPE_BOOLEAN)) |
761 | { | 810 | { |
762 | int n = *((int *)value); | 811 | int n = *((int *) value); |
763 | if (state->streamInfo->audioChannels == -1) | 812 | if (state->streamInfo->audioChannels == -1) |
764 | state->streamInfo->audioChannels = (n == 0) ? 1 : 2; | 813 | state->streamInfo->audioChannels = (n == 0) ? 1 : 2; |
765 | } | 814 | } |
@@ -769,57 +818,59 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
769 | (state->currentKeyType != EXTRACTOR_METATYPE_RESERVED)) | 818 | (state->currentKeyType != EXTRACTOR_METATYPE_RESERVED)) |
770 | { | 819 | { |
771 | s = NULL; | 820 | s = NULL; |
772 | switch (type) { | 821 | switch (type) |
773 | case ASTYPE_NUMBER: | 822 | { |
823 | case ASTYPE_NUMBER: | ||
774 | { | 824 | { |
775 | double n = *((double *)value); | 825 | double n = *((double *) value); |
776 | s = tmpstr; | 826 | s = tmpstr; |
777 | if (state->currentKeyType == EXTRACTOR_METATYPE_DURATION) | 827 | if (state->currentKeyType == EXTRACTOR_METATYPE_DURATION) |
778 | snprintf(tmpstr, sizeof(tmpstr), "%.2f s", n); | 828 | snprintf (tmpstr, sizeof(tmpstr), "%.2f s", n); |
779 | else | 829 | else |
780 | snprintf(tmpstr, sizeof(tmpstr), "%f", n); | 830 | snprintf (tmpstr, sizeof(tmpstr), "%f", n); |
781 | break; | 831 | break; |
782 | } | 832 | } |
783 | case ASTYPE_STRING: | 833 | case ASTYPE_STRING: |
784 | { | 834 | { |
785 | s = (char *)value; | 835 | s = (char *) value; |
786 | break; | 836 | break; |
787 | } | 837 | } |
788 | case ASTYPE_DATE: | 838 | case ASTYPE_DATE: |
789 | { | 839 | { |
790 | void **tmp = (void **)value; | 840 | void **tmp = (void **) value; |
791 | double *millis; | 841 | double *millis; |
792 | short *tz; | 842 | short *tz; |
793 | millis = (double *)tmp[0]; | 843 | millis = (double *) tmp[0]; |
794 | tz = (short *)tmp[1]; | 844 | tz = (short *) tmp[1]; |
795 | if (0 == flv_to_iso_date(*millis, *tz, tmpstr, sizeof(tmpstr))) | 845 | if (0 == flv_to_iso_date (*millis, *tz, tmpstr, sizeof(tmpstr))) |
796 | s = tmpstr; | 846 | s = tmpstr; |
797 | break; | 847 | break; |
798 | } | 848 | } |
799 | } | 849 | } |
800 | if ( (s != NULL) && | 850 | if ( (s != NULL) && |
801 | (state->ret == 0) ) | 851 | (state->ret == 0) ) |
802 | state->ret = state->proc (state->proc_cls, | 852 | state->ret = state->proc (state->proc_cls, |
803 | "flv", | 853 | "flv", |
804 | state->currentKeyType, | 854 | state->currentKeyType, |
805 | EXTRACTOR_METAFORMAT_UTF8, | 855 | EXTRACTOR_METAFORMAT_UTF8, |
806 | "text/plain", | 856 | "text/plain", |
807 | s, | 857 | s, |
808 | strlen (s) + 1); | 858 | strlen (s) + 1); |
809 | } | 859 | } |
810 | state->currentKeyType = EXTRACTOR_METATYPE_RESERVED; | 860 | state->currentKeyType = EXTRACTOR_METATYPE_RESERVED; |
811 | state->currentAttribute = FLV_NONE; | 861 | state->currentAttribute = FLV_NONE; |
812 | 862 | ||
813 | if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || | 863 | if ((type == ASTYPE_ARRAY) || (type == ASTYPE_MIXEDARRAY) || |
814 | type == ASTYPE_OBJECT) | 864 | (type == ASTYPE_OBJECT) ) |
815 | state->parsingDepth--; | 865 | state->parsingDepth--; |
816 | } | 866 | } |
817 | 867 | ||
868 | |||
818 | static int | 869 | static int |
819 | handleMetaBody(const unsigned char *data, size_t len, | 870 | handleMetaBody (const unsigned char *data, size_t len, |
820 | FLVStreamInfo *stinfo, | 871 | FLVStreamInfo *stinfo, |
821 | EXTRACTOR_MetaDataProcessor proc, | 872 | EXTRACTOR_MetaDataProcessor proc, |
822 | void *proc_cls) | 873 | void *proc_cls) |
823 | { | 874 | { |
824 | AMFParserHandler handler; | 875 | AMFParserHandler handler; |
825 | FLVMetaParserState pstate; | 876 | FLVMetaParserState pstate; |
@@ -836,12 +887,14 @@ handleMetaBody(const unsigned char *data, size_t len, | |||
836 | handler.as_key_callback = &handleASKey; | 887 | handler.as_key_callback = &handleASKey; |
837 | handler.as_end_callback = &handleASEnd; | 888 | handler.as_end_callback = &handleASEnd; |
838 | 889 | ||
839 | while (len > 0 && parse_amf(&data, &len, &handler) == 0); | 890 | while (len > 0 && parse_amf (&data, &len, &handler) == 0) |
891 | ; | ||
840 | if (pstate.ret != 0) | 892 | if (pstate.ret != 0) |
841 | return 1; | 893 | return 1; |
842 | return 0; | 894 | return 0; |
843 | } | 895 | } |
844 | 896 | ||
897 | |||
845 | static char *FLVAudioCodecs[] = { | 898 | static char *FLVAudioCodecs[] = { |
846 | "Uncompressed", | 899 | "Uncompressed", |
847 | "ADPCM", | 900 | "ADPCM", |
@@ -875,19 +928,21 @@ static char *FLVAudioSampleRates[] = { | |||
875 | }; | 928 | }; |
876 | 929 | ||
877 | static void | 930 | static void |
878 | handleAudioBody(const unsigned char *data, size_t len, | 931 | handleAudioBody (const unsigned char *data, size_t len, |
879 | FLVStreamInfo *stinfo) | 932 | FLVStreamInfo *stinfo) |
880 | { | 933 | { |
881 | stinfo->audioChannels = (*data & 0x01) + 1; | 934 | stinfo->audioChannels = (*data & 0x01) + 1; |
882 | stinfo->audioSampleBits = (*data & 0x02) >> 1; | 935 | stinfo->audioSampleBits = (*data & 0x02) >> 1; |
883 | stinfo->audioRate = (*data & 0x0C) >> 2; | 936 | stinfo->audioRate = (*data & 0x0C) >> 2; |
884 | stinfo->audioCodec = (*data & 0xF0) >> 4; | 937 | stinfo->audioCodec = (*data & 0xF0) >> 4; |
885 | if (stinfo->audioCodecStr != NULL) { | 938 | if (stinfo->audioCodecStr != NULL) |
886 | free(stinfo->audioCodecStr); | 939 | { |
940 | free (stinfo->audioCodecStr); | ||
887 | stinfo->audioCodecStr = NULL; | 941 | stinfo->audioCodecStr = NULL; |
888 | } | 942 | } |
889 | } | 943 | } |
890 | 944 | ||
945 | |||
891 | static char *FLVVideoCodecs[] = { | 946 | static char *FLVVideoCodecs[] = { |
892 | NULL, | 947 | NULL, |
893 | NULL, | 948 | NULL, |
@@ -911,8 +966,8 @@ static int sorenson_predefined_res[][2] = { | |||
911 | }; | 966 | }; |
912 | 967 | ||
913 | static void | 968 | static void |
914 | handleVideoBody(const unsigned char *data, size_t len, | 969 | handleVideoBody (const unsigned char *data, size_t len, |
915 | FLVStreamInfo *stinfo) | 970 | FLVStreamInfo *stinfo) |
916 | { | 971 | { |
917 | int codecId, frameType; | 972 | int codecId, frameType; |
918 | 973 | ||
@@ -921,84 +976,94 @@ handleVideoBody(const unsigned char *data, size_t len, | |||
921 | data++; | 976 | data++; |
922 | 977 | ||
923 | /* try to get video dimensions */ | 978 | /* try to get video dimensions */ |
924 | switch (codecId) { | 979 | switch (codecId) |
925 | case 0x02: /* Sorenson */ | 980 | { |
926 | if (len < 9) | 981 | case 0x02: /* Sorenson */ |
927 | break; | 982 | if (len < 9) |
928 | if (frameType == 1) { | ||
929 | int start_code = (data[0] << 9) | (data[1] << 1) | ((data[2] >> 7)&0x1); | ||
930 | int version = (data[2] & 0x7C) >> 2; | ||
931 | int frame_size = ((data[3] & 0x03) << 1) | (data[4] >> 7); | ||
932 | if (start_code != 0x00000001) | ||
933 | break; | ||
934 | if (!(version == 0 || version == 1)) | ||
935 | break; | ||
936 | if (frame_size == 0) { | ||
937 | stinfo->videoWidth = ((data[4] & 0x7F) >> 1) | (data[5] >> 7); | ||
938 | stinfo->videoHeight = ((data[5] & 0x7F) >> 1) | (data[6] >> 7); | ||
939 | } | ||
940 | else if (frame_size == 1) { | ||
941 | stinfo->videoWidth = ((data[4] & 0x7F) << 9) | (data[5] << 1) | | ||
942 | (data[6] >> 7); | ||
943 | stinfo->videoHeight = ((data[6] & 0x7F) << 9) | (data[7] << 1) | | ||
944 | (data[8] >> 7); | ||
945 | } | ||
946 | else { | ||
947 | stinfo->videoWidth = sorenson_predefined_res[frame_size][0]; | ||
948 | stinfo->videoHeight = sorenson_predefined_res[frame_size][1]; | ||
949 | } | ||
950 | } | ||
951 | break; | 983 | break; |
952 | case 0x03: /* ScreenVideo */ | 984 | if (frameType == 1) |
953 | if (len < 5) | 985 | { |
986 | int start_code = (data[0] << 9) | (data[1] << 1) | ((data[2] >> 7) & 0x1); | ||
987 | int version = (data[2] & 0x7C) >> 2; | ||
988 | int frame_size = ((data[3] & 0x03) << 1) | (data[4] >> 7); | ||
989 | if (start_code != 0x00000001) | ||
954 | break; | 990 | break; |
955 | stinfo->videoWidth = readInt16(&data) & 0x0FFF; | 991 | if (! ((version == 0) || (version == 1) )) |
956 | stinfo->videoHeight = readInt16(&data) & 0x0FFF; | 992 | break; |
993 | if (frame_size == 0) | ||
994 | { | ||
995 | stinfo->videoWidth = ((data[4] & 0x7F) >> 1) | (data[5] >> 7); | ||
996 | stinfo->videoHeight = ((data[5] & 0x7F) >> 1) | (data[6] >> 7); | ||
997 | } | ||
998 | else if (frame_size == 1) | ||
999 | { | ||
1000 | stinfo->videoWidth = ((data[4] & 0x7F) << 9) | (data[5] << 1) | ||
1001 | | (data[6] >> 7); | ||
1002 | stinfo->videoHeight = ((data[6] & 0x7F) << 9) | (data[7] << 1) | ||
1003 | | (data[8] >> 7); | ||
1004 | } | ||
1005 | else | ||
1006 | { | ||
1007 | stinfo->videoWidth = sorenson_predefined_res[frame_size][0]; | ||
1008 | stinfo->videoHeight = sorenson_predefined_res[frame_size][1]; | ||
1009 | } | ||
1010 | } | ||
1011 | break; | ||
1012 | case 0x03: /* ScreenVideo */ | ||
1013 | if (len < 5) | ||
957 | break; | 1014 | break; |
958 | case 0x04: /* On2 VP6 */ | 1015 | stinfo->videoWidth = readInt16 (&data) & 0x0FFF; |
959 | case 0x05: | 1016 | stinfo->videoHeight = readInt16 (&data) & 0x0FFF; |
1017 | break; | ||
1018 | case 0x04: /* On2 VP6 */ | ||
1019 | case 0x05: | ||
960 | { | 1020 | { |
961 | unsigned char dim_adj; | 1021 | unsigned char dim_adj; |
962 | if (len < 10) | 1022 | if (len < 10) |
963 | break; | 1023 | break; |
964 | dim_adj = *data++; | 1024 | dim_adj = *data++; |
965 | if ((frameType == 1) && ((data[0] & 0x80) == 0)) { | 1025 | if ((frameType == 1) && ((data[0] & 0x80) == 0)) |
1026 | { | ||
966 | /* see ffmpeg vp6 decoder */ | 1027 | /* see ffmpeg vp6 decoder */ |
967 | int separated_coeff = data[0] & 0x01; | 1028 | int separated_coeff = data[0] & 0x01; |
968 | int filter_header = data[1] & 0x06; | 1029 | int filter_header = data[1] & 0x06; |
969 | /*int interlaced = data[1] & 0x01; TODO: used in flv ever? */ | 1030 | /*int interlaced = data[1] & 0x01; TODO: used in flv ever? */ |
970 | if (separated_coeff || !filter_header) { | 1031 | if (separated_coeff || ! filter_header) |
1032 | { | ||
971 | data += 2; | 1033 | data += 2; |
972 | } | 1034 | } |
973 | /* XXX encoded/displayed dimensions might vary, but which are the | 1035 | /* XXX encoded/displayed dimensions might vary, but which are the |
974 | * right ones? */ | 1036 | * right ones? */ |
975 | stinfo->videoWidth = (data[3]*16) - (dim_adj>>4); | 1037 | stinfo->videoWidth = (data[3] * 16) - (dim_adj >> 4); |
976 | stinfo->videoHeight = (data[2]*16) - (dim_adj&0x0F); | 1038 | stinfo->videoHeight = (data[2] * 16) - (dim_adj & 0x0F); |
977 | } | 1039 | } |
978 | break; | 1040 | break; |
979 | } | 1041 | } |
980 | default: | 1042 | default: |
981 | break; | 1043 | break; |
982 | } | 1044 | } |
983 | 1045 | ||
984 | stinfo->videoCodec = codecId; | 1046 | stinfo->videoCodec = codecId; |
985 | if (stinfo->videoCodecStr != NULL) { | 1047 | if (stinfo->videoCodecStr != NULL) |
986 | free(stinfo->videoCodecStr); | 1048 | { |
1049 | free (stinfo->videoCodecStr); | ||
987 | stinfo->videoCodecStr = NULL; | 1050 | stinfo->videoCodecStr = NULL; |
988 | } | 1051 | } |
989 | } | 1052 | } |
990 | 1053 | ||
991 | static int readFLVTag(const unsigned char **data, | 1054 | |
992 | const unsigned char *end, | 1055 | static int |
993 | FLVStreamInfo *stinfo, | 1056 | readFLVTag (const unsigned char **data, |
994 | EXTRACTOR_MetaDataProcessor proc, | 1057 | const unsigned char *end, |
995 | void *proc_cls) | 1058 | FLVStreamInfo *stinfo, |
1059 | EXTRACTOR_MetaDataProcessor proc, | ||
1060 | void *proc_cls) | ||
996 | { | 1061 | { |
997 | const unsigned char *ptr = *data; | 1062 | const unsigned char *ptr = *data; |
998 | FLVTagHeader header; | 1063 | FLVTagHeader header; |
999 | int ret = 0; | 1064 | int ret = 0; |
1000 | 1065 | ||
1001 | if (readFLVTagHeader(&ptr, end, &header) == -1) | 1066 | if (readFLVTagHeader (&ptr, end, &header) == -1) |
1002 | return -1; | 1067 | return -1; |
1003 | 1068 | ||
1004 | if ((ptr + header.bodyLength) > end) | 1069 | if ((ptr + header.bodyLength) > end) |
@@ -1006,17 +1071,17 @@ static int readFLVTag(const unsigned char **data, | |||
1006 | 1071 | ||
1007 | switch (header.type) | 1072 | switch (header.type) |
1008 | { | 1073 | { |
1009 | case FLV_TAG_TYPE_AUDIO: | 1074 | case FLV_TAG_TYPE_AUDIO: |
1010 | handleAudioBody(ptr, header.bodyLength, stinfo); | 1075 | handleAudioBody (ptr, header.bodyLength, stinfo); |
1011 | break; | 1076 | break; |
1012 | case FLV_TAG_TYPE_VIDEO: | 1077 | case FLV_TAG_TYPE_VIDEO: |
1013 | handleVideoBody(ptr, header.bodyLength, stinfo); | 1078 | handleVideoBody (ptr, header.bodyLength, stinfo); |
1014 | break; | 1079 | break; |
1015 | case FLV_TAG_TYPE_META: | 1080 | case FLV_TAG_TYPE_META: |
1016 | ret = handleMetaBody(ptr, header.bodyLength, stinfo, proc, proc_cls); | 1081 | ret = handleMetaBody (ptr, header.bodyLength, stinfo, proc, proc_cls); |
1017 | break; | 1082 | break; |
1018 | default: | 1083 | default: |
1019 | break; | 1084 | break; |
1020 | } | 1085 | } |
1021 | 1086 | ||
1022 | ptr += header.bodyLength; | 1087 | ptr += header.bodyLength; |
@@ -1024,129 +1089,149 @@ static int readFLVTag(const unsigned char **data, | |||
1024 | return ret; | 1089 | return ret; |
1025 | } | 1090 | } |
1026 | 1091 | ||
1092 | |||
1027 | #define MAX_FLV_FORMAT_LINE 80 | 1093 | #define MAX_FLV_FORMAT_LINE 80 |
1028 | static char * printVideoFormat(FLVStreamInfo *stinfo) | 1094 | static char * |
1095 | printVideoFormat (FLVStreamInfo *stinfo) | ||
1029 | { | 1096 | { |
1030 | char s[MAX_FLV_FORMAT_LINE+1]; | 1097 | char s[MAX_FLV_FORMAT_LINE + 1]; |
1031 | int n; | 1098 | int n; |
1032 | size_t len = MAX_FLV_FORMAT_LINE; | 1099 | size_t len = MAX_FLV_FORMAT_LINE; |
1033 | 1100 | ||
1034 | n = 0; | 1101 | n = 0; |
1035 | /* some files seem to specify only the width or the height, print '?' for | 1102 | /* some files seem to specify only the width or the height, print '?' for |
1036 | * the unknown dimension */ | 1103 | * the unknown dimension */ |
1037 | if (stinfo->videoWidth != -1 || stinfo->videoHeight != -1) { | 1104 | if ((stinfo->videoWidth != -1) || (stinfo->videoHeight != -1)) |
1038 | if (n < len) { | 1105 | { |
1106 | if (n < len) | ||
1107 | { | ||
1039 | if (stinfo->videoWidth != -1) | 1108 | if (stinfo->videoWidth != -1) |
1040 | n += snprintf(s+n, len-n, "%d", stinfo->videoWidth); | 1109 | n += snprintf (s + n, len - n, "%d", stinfo->videoWidth); |
1041 | else | 1110 | else |
1042 | n += snprintf(s+n, len-n, "?"); | 1111 | n += snprintf (s + n, len - n, "?"); |
1043 | } | 1112 | } |
1044 | 1113 | ||
1045 | if (n < len) { | 1114 | if (n < len) |
1115 | { | ||
1046 | if (stinfo->videoHeight != -1) | 1116 | if (stinfo->videoHeight != -1) |
1047 | n += snprintf(s+n, len-n, "x%d", stinfo->videoHeight); | 1117 | n += snprintf (s + n, len - n, "x%d", stinfo->videoHeight); |
1048 | else | 1118 | else |
1049 | n += snprintf(s+n, len-n, "x?"); | 1119 | n += snprintf (s + n, len - n, "x?"); |
1050 | } | 1120 | } |
1051 | } | 1121 | } |
1052 | 1122 | ||
1053 | if (stinfo->videoFrameRate != 0.0 && n < len) { | 1123 | if ((stinfo->videoFrameRate != 0.0) && (n < len)) |
1124 | { | ||
1054 | if (n > 0) | 1125 | if (n > 0) |
1055 | n += snprintf(s+n, len-n, ", "); | 1126 | n += snprintf (s + n, len - n, ", "); |
1056 | if (n < len) | 1127 | if (n < len) |
1057 | n += snprintf(s+n, len-n, "%0.2f fps", stinfo->videoFrameRate); | 1128 | n += snprintf (s + n, len - n, "%0.2f fps", stinfo->videoFrameRate); |
1058 | } | 1129 | } |
1059 | 1130 | ||
1060 | if (stinfo->videoCodec > -1 && stinfo->videoCodec < 8 && | 1131 | if ((stinfo->videoCodec > -1) && (stinfo->videoCodec < 8) && |
1061 | FLVVideoCodecs[stinfo->videoCodec] != NULL && n < len) { | 1132 | (FLVVideoCodecs[stinfo->videoCodec] != NULL) && (n < len) ) |
1133 | { | ||
1062 | if (n > 0) | 1134 | if (n > 0) |
1063 | n += snprintf(s+n, len-n, ", "); | 1135 | n += snprintf (s + n, len - n, ", "); |
1064 | if (n < len) | 1136 | if (n < len) |
1065 | n += snprintf(s+n, len-n, "%s", FLVVideoCodecs[stinfo->videoCodec]); | 1137 | n += snprintf (s + n, len - n, "%s", FLVVideoCodecs[stinfo->videoCodec]); |
1066 | } | 1138 | } |
1067 | else if (stinfo->videoCodecStr != NULL && n < len) { | 1139 | else if ((stinfo->videoCodecStr != NULL) && (n < len)) |
1140 | { | ||
1068 | if (n > 0) | 1141 | if (n > 0) |
1069 | n += snprintf(s+n, len-n, ", "); | 1142 | n += snprintf (s + n, len - n, ", "); |
1070 | if (n < len) | 1143 | if (n < len) |
1071 | n += snprintf(s+n, len-n, "%s", stinfo->videoCodecStr); | 1144 | n += snprintf (s + n, len - n, "%s", stinfo->videoCodecStr); |
1072 | } | 1145 | } |
1073 | 1146 | ||
1074 | if (stinfo->videoDataRate != 0.0 && n < len) { | 1147 | if ((stinfo->videoDataRate != 0.0) && (n < len)) |
1148 | { | ||
1075 | if (n > 0) | 1149 | if (n > 0) |
1076 | n += snprintf(s+n, len-n, ", "); | 1150 | n += snprintf (s + n, len - n, ", "); |
1077 | if (n < len) | 1151 | if (n < len) |
1078 | n += snprintf(s+n, len-n, "%.4f kbps", stinfo->videoDataRate); | 1152 | n += snprintf (s + n, len - n, "%.4f kbps", stinfo->videoDataRate); |
1079 | } | 1153 | } |
1080 | 1154 | ||
1081 | if (n == 0) | 1155 | if (n == 0) |
1082 | return NULL; | 1156 | return NULL; |
1083 | return strdup(s); | 1157 | return strdup (s); |
1084 | } | 1158 | } |
1085 | 1159 | ||
1086 | static char * printAudioFormat(FLVStreamInfo *stinfo) | 1160 | |
1161 | static char * | ||
1162 | printAudioFormat (FLVStreamInfo *stinfo) | ||
1087 | { | 1163 | { |
1088 | char s[MAX_FLV_FORMAT_LINE+1]; | 1164 | char s[MAX_FLV_FORMAT_LINE + 1]; |
1089 | int n; | 1165 | int n; |
1090 | size_t len = MAX_FLV_FORMAT_LINE; | 1166 | size_t len = MAX_FLV_FORMAT_LINE; |
1091 | 1167 | ||
1092 | n = 0; | 1168 | n = 0; |
1093 | if ( (stinfo->audioRate != -1) && (n < len)) { | 1169 | if ( (stinfo->audioRate != -1) && (n < len)) |
1094 | n += snprintf(s+n, len-n, "%s Hz", FLVAudioSampleRates[stinfo->audioRate]); | 1170 | { |
1171 | n += snprintf (s + n, len - n, "%s Hz", | ||
1172 | FLVAudioSampleRates[stinfo->audioRate]); | ||
1095 | } | 1173 | } |
1096 | 1174 | ||
1097 | if ((stinfo->audioSampleBits != -1) && (n < len)) { | 1175 | if ((stinfo->audioSampleBits != -1) && (n < len)) |
1176 | { | ||
1098 | if (n > 0) | 1177 | if (n > 0) |
1099 | n += snprintf(s+n, len-n, ", "); | 1178 | n += snprintf (s + n, len - n, ", "); |
1100 | if (n < len) | 1179 | if (n < len) |
1101 | n += snprintf(s+n, len-n, "%s", | 1180 | n += snprintf (s + n, len - n, "%s", |
1102 | FLVAudioSampleSizes[stinfo->audioSampleBits]); | 1181 | FLVAudioSampleSizes[stinfo->audioSampleBits]); |
1103 | } | 1182 | } |
1104 | 1183 | ||
1105 | if ((stinfo->audioChannels != -1) && (n < len)) { | 1184 | if ((stinfo->audioChannels != -1) && (n < len)) |
1185 | { | ||
1106 | if (n > 0) | 1186 | if (n > 0) |
1107 | n += snprintf(s+n, len-n, ", "); | 1187 | n += snprintf (s + n, len - n, ", "); |
1108 | if (n < len) { | 1188 | if (n < len) |
1109 | if (stinfo->audioChannels >= 1 && stinfo->audioChannels <= 2) | 1189 | { |
1110 | n += snprintf(s+n, len-n, "%s", | 1190 | if ((stinfo->audioChannels >= 1) && (stinfo->audioChannels <= 2)) |
1111 | FLVAudioChannels[stinfo->audioChannels-1]); | 1191 | n += snprintf (s + n, len - n, "%s", |
1192 | FLVAudioChannels[stinfo->audioChannels - 1]); | ||
1112 | else | 1193 | else |
1113 | n += snprintf(s+n, len-n, "%d", | 1194 | n += snprintf (s + n, len - n, "%d", |
1114 | stinfo->audioChannels); | 1195 | stinfo->audioChannels); |
1115 | } | 1196 | } |
1116 | } | 1197 | } |
1117 | 1198 | ||
1118 | if ((stinfo->audioCodec > -1) && (stinfo->audioCodec < 12) && | 1199 | if ((stinfo->audioCodec > -1) && (stinfo->audioCodec < 12) && |
1119 | (FLVAudioCodecs[stinfo->audioCodec] != NULL) && (n < len)) { | 1200 | (FLVAudioCodecs[stinfo->audioCodec] != NULL) && (n < len)) |
1201 | { | ||
1120 | if (n > 0) | 1202 | if (n > 0) |
1121 | n += snprintf(s+n, len-n, ", "); | 1203 | n += snprintf (s + n, len - n, ", "); |
1122 | if (n < len) | 1204 | if (n < len) |
1123 | n += snprintf(s+n, len-n, "%s", FLVAudioCodecs[stinfo->audioCodec]); | 1205 | n += snprintf (s + n, len - n, "%s", FLVAudioCodecs[stinfo->audioCodec]); |
1124 | } | 1206 | } |
1125 | else if ((stinfo->audioCodecStr != NULL) && (n < len)) { | 1207 | else if ((stinfo->audioCodecStr != NULL) && (n < len)) |
1208 | { | ||
1126 | if (n > 0) | 1209 | if (n > 0) |
1127 | n += snprintf(s+n, len-n, ", "); | 1210 | n += snprintf (s + n, len - n, ", "); |
1128 | if (n < len) | 1211 | if (n < len) |
1129 | n += snprintf(s+n, len-n, "%s", stinfo->audioCodecStr); | 1212 | n += snprintf (s + n, len - n, "%s", stinfo->audioCodecStr); |
1130 | } | 1213 | } |
1131 | 1214 | ||
1132 | if ((stinfo->audioDataRate != 0.0) && (n < len)) { | 1215 | if ((stinfo->audioDataRate != 0.0) && (n < len)) |
1216 | { | ||
1133 | if (n > 0) | 1217 | if (n > 0) |
1134 | n += snprintf(s+n, len-n, ", "); | 1218 | n += snprintf (s + n, len - n, ", "); |
1135 | if (n < len) | 1219 | if (n < len) |
1136 | n += snprintf(s+n, len-n, "%.4f kbps", stinfo->audioDataRate); | 1220 | n += snprintf (s + n, len - n, "%.4f kbps", stinfo->audioDataRate); |
1137 | } | 1221 | } |
1138 | 1222 | ||
1139 | if (n == 0) | 1223 | if (n == 0) |
1140 | return NULL; | 1224 | return NULL; |
1141 | return strdup(s); | 1225 | return strdup (s); |
1142 | } | 1226 | } |
1143 | 1227 | ||
1144 | int | 1228 | |
1229 | int | ||
1145 | EXTRACTOR_flv_extract (const unsigned char *data, | 1230 | EXTRACTOR_flv_extract (const unsigned char *data, |
1146 | size_t size, | 1231 | size_t size, |
1147 | EXTRACTOR_MetaDataProcessor proc, | 1232 | EXTRACTOR_MetaDataProcessor proc, |
1148 | void *proc_cls, | 1233 | void *proc_cls, |
1149 | const char *options) | 1234 | const char *options) |
1150 | { | 1235 | { |
1151 | const unsigned char *ptr; | 1236 | const unsigned char *ptr; |
1152 | const unsigned char *end; | 1237 | const unsigned char *end; |
@@ -1159,19 +1244,19 @@ EXTRACTOR_flv_extract (const unsigned char *data, | |||
1159 | ptr = data; | 1244 | ptr = data; |
1160 | end = ptr + size; | 1245 | end = ptr + size; |
1161 | 1246 | ||
1162 | if (readFLVHeader(&ptr, end, &header) == -1) | 1247 | if (readFLVHeader (&ptr, end, &header) == -1) |
1163 | return 0; | 1248 | return 0; |
1164 | 1249 | ||
1165 | if (memcmp(header.signature, FLV_SIGNATURE, 3) != 0) | 1250 | if (memcmp (header.signature, FLV_SIGNATURE, 3) != 0) |
1166 | return 0; | 1251 | return 0; |
1167 | 1252 | ||
1168 | if (0 != proc (proc_cls, | 1253 | if (0 != proc (proc_cls, |
1169 | "flv", | 1254 | "flv", |
1170 | EXTRACTOR_METATYPE_MIMETYPE, | 1255 | EXTRACTOR_METATYPE_MIMETYPE, |
1171 | EXTRACTOR_METAFORMAT_UTF8, | 1256 | EXTRACTOR_METAFORMAT_UTF8, |
1172 | "text/plain", | 1257 | "text/plain", |
1173 | "video/x-flv", | 1258 | "video/x-flv", |
1174 | strlen ("video/x-flv") + 1)) | 1259 | strlen ("video/x-flv") + 1)) |
1175 | return 0; | 1260 | return 0; |
1176 | if (header.version != 1) | 1261 | if (header.version != 1) |
1177 | return 0; | 1262 | return 0; |
@@ -1191,7 +1276,8 @@ EXTRACTOR_flv_extract (const unsigned char *data, | |||
1191 | stinfo.audioChannels = -1; | 1276 | stinfo.audioChannels = -1; |
1192 | stinfo.audioDataRate = 0.0; | 1277 | stinfo.audioDataRate = 0.0; |
1193 | ret = 0; | 1278 | ret = 0; |
1194 | while (ptr < end) { | 1279 | while (ptr < end) |
1280 | { | ||
1195 | if (-1 == (ret = readFLVTag (&ptr, end, &stinfo, proc, proc_cls))) | 1281 | if (-1 == (ret = readFLVTag (&ptr, end, &stinfo, proc, proc_cls))) |
1196 | break; | 1282 | break; |
1197 | if (readPreviousTagSize (&ptr, end, &prev_tag_size) == -1) | 1283 | if (readPreviousTagSize (&ptr, end, &prev_tag_size) == -1) |
@@ -1201,35 +1287,35 @@ EXTRACTOR_flv_extract (const unsigned char *data, | |||
1201 | return 1; | 1287 | return 1; |
1202 | s = printVideoFormat (&stinfo); | 1288 | s = printVideoFormat (&stinfo); |
1203 | if (s != NULL) | 1289 | if (s != NULL) |
1290 | { | ||
1291 | if (0 != proc (proc_cls, | ||
1292 | "flv", | ||
1293 | EXTRACTOR_METATYPE_RESOURCE_TYPE, | ||
1294 | EXTRACTOR_METAFORMAT_UTF8, | ||
1295 | "text/plain", | ||
1296 | s, | ||
1297 | strlen (s) + 1)) | ||
1204 | { | 1298 | { |
1205 | if (0 != proc (proc_cls, | ||
1206 | "flv", | ||
1207 | EXTRACTOR_METATYPE_RESOURCE_TYPE, | ||
1208 | EXTRACTOR_METAFORMAT_UTF8, | ||
1209 | "text/plain", | ||
1210 | s, | ||
1211 | strlen (s)+1)) | ||
1212 | { | ||
1213 | free (s); | ||
1214 | return 1; | ||
1215 | } | ||
1216 | free (s); | 1299 | free (s); |
1300 | return 1; | ||
1217 | } | 1301 | } |
1302 | free (s); | ||
1303 | } | ||
1218 | s = printAudioFormat (&stinfo); | 1304 | s = printAudioFormat (&stinfo); |
1219 | if (s != NULL) | 1305 | if (s != NULL) |
1306 | { | ||
1307 | if (0 != proc (proc_cls, | ||
1308 | "flv", | ||
1309 | EXTRACTOR_METATYPE_RESOURCE_TYPE, | ||
1310 | EXTRACTOR_METAFORMAT_UTF8, | ||
1311 | "text/plain", | ||
1312 | s, | ||
1313 | strlen (s) + 1)) | ||
1220 | { | 1314 | { |
1221 | if (0 != proc (proc_cls, | ||
1222 | "flv", | ||
1223 | EXTRACTOR_METATYPE_RESOURCE_TYPE, | ||
1224 | EXTRACTOR_METAFORMAT_UTF8, | ||
1225 | "text/plain", | ||
1226 | s, | ||
1227 | strlen (s)+1)) | ||
1228 | { | ||
1229 | free (s); | ||
1230 | return 1; | ||
1231 | } | ||
1232 | free (s); | 1315 | free (s); |
1316 | return 1; | ||
1233 | } | 1317 | } |
1318 | free (s); | ||
1319 | } | ||
1234 | return 0; | 1320 | return 0; |
1235 | } | 1321 | } |
diff --git a/src/plugins/old/mkv_extractor.c b/src/plugins/old/mkv_extractor.c index 9e2f1f9..ff052dc 100644 --- a/src/plugins/old/mkv_extractor.c +++ b/src/plugins/old/mkv_extractor.c | |||
@@ -18,17 +18,21 @@ | |||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * Made by Gabriel Peixoto | 22 | * Made by Gabriel Peixoto |
23 | * Using AVInfo 1.x code. Copyright (c) 2004 George Shuklin. | 23 | * Using AVInfo 1.x code. Copyright (c) 2004 George Shuklin. |
24 | * | 24 | * |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "extractor.h" | 28 | #include "extractor.h" |
29 | #include <stdint.h> | 29 | #include <stdint.h> |
30 | 30 | ||
31 | #define ADD(s,t) do { if (0 != (ret = proc (proc_cls, "mkv", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto EXIT; } while (0) | 31 | #define ADD(s,t) do { if (0 != (ret = proc (proc_cls, "mkv", t, \ |
32 | EXTRACTOR_METAFORMAT_UTF8, \ | ||
33 | "text/plain", s, strlen (s) \ | ||
34 | + 1))) goto EXIT; \ | ||
35 | } while (0) | ||
32 | 36 | ||
33 | /** | 37 | /** |
34 | * FIXME: document | 38 | * FIXME: document |
@@ -98,27 +102,29 @@ enum | |||
98 | */ | 102 | */ |
99 | static size_t | 103 | static size_t |
100 | VINTparse (const unsigned char *buffer, size_t start, size_t end, | 104 | VINTparse (const unsigned char *buffer, size_t start, size_t end, |
101 | int64_t * result, int flag) | 105 | int64_t *result, int flag) |
102 | { | 106 | { |
103 | static const unsigned char mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 }; | 107 | static const unsigned char mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, |
104 | static const unsigned char imask[8] = { 0x7F, 0x3F, 0x1F, 0xF, 0x7, 0x3, 0x1, 00 }; | 108 | 0x1 }; |
109 | static const unsigned char imask[8] = { 0x7F, 0x3F, 0x1F, 0xF, 0x7, 0x3, 0x1, | ||
110 | 00 }; | ||
105 | int vint_width; | 111 | int vint_width; |
106 | unsigned int c; | 112 | unsigned int c; |
107 | int64_t temp; | 113 | int64_t temp; |
108 | unsigned char tempc; | 114 | unsigned char tempc; |
109 | 115 | ||
110 | if (end - start < 2) | 116 | if (end - start < 2) |
111 | return 0; /*ops */ | 117 | return 0; /*ops */ |
112 | 118 | ||
113 | vint_width = 0; | 119 | vint_width = 0; |
114 | for (c = 0; c < 8; c++) | 120 | for (c = 0; c < 8; c++) |
115 | if (!(buffer[start] & mask[c])) | 121 | if (! (buffer[start] & mask[c])) |
116 | vint_width++; | 122 | vint_width++; |
117 | else | 123 | else |
118 | break; | 124 | break; |
119 | if ( (vint_width >= 8) || (vint_width + start + 1 >= end) ) | 125 | if ( (vint_width >= 8) || (vint_width + start + 1 >= end) ) |
120 | return 0; | 126 | return 0; |
121 | 127 | ||
122 | *result = 0; | 128 | *result = 0; |
123 | for (c = 0; c < vint_width; c++) | 129 | for (c = 0; c < vint_width; c++) |
124 | { | 130 | { |
@@ -139,7 +145,7 @@ VINTparse (const unsigned char *buffer, size_t start, size_t end, | |||
139 | */ | 145 | */ |
140 | static unsigned int | 146 | static unsigned int |
141 | elementRead (const unsigned char *buffer, size_t start, size_t end, | 147 | elementRead (const unsigned char *buffer, size_t start, size_t end, |
142 | uint32_t *id, int64_t * size) | 148 | uint32_t *id, int64_t *size) |
143 | { | 149 | { |
144 | int64_t tempID; | 150 | int64_t tempID; |
145 | int64_t tempsize; | 151 | int64_t tempsize; |
@@ -147,12 +153,12 @@ elementRead (const unsigned char *buffer, size_t start, size_t end, | |||
147 | size_t size_offset; | 153 | size_t size_offset; |
148 | 154 | ||
149 | tempID = 0; | 155 | tempID = 0; |
150 | 156 | ||
151 | id_offset = VINTparse (buffer, start, end, &tempID, 0); | 157 | id_offset = VINTparse (buffer, start, end, &tempID, 0); |
152 | if (!id_offset) | 158 | if (! id_offset) |
153 | return 0; | 159 | return 0; |
154 | size_offset = VINTparse (buffer, start + id_offset, end, &tempsize, 1); | 160 | size_offset = VINTparse (buffer, start + id_offset, end, &tempsize, 1); |
155 | if (!size_offset) | 161 | if (! size_offset) |
156 | return 0; | 162 | return 0; |
157 | *id = (uint32_t) tempID; | 163 | *id = (uint32_t) tempID; |
158 | *size = tempsize; | 164 | *size = tempsize; |
@@ -172,10 +178,11 @@ getInt (const unsigned char *buffer, size_t start, size_t size) | |||
172 | 178 | ||
173 | result = 0; | 179 | result = 0; |
174 | for (c = 1; c <= size; c++) | 180 | for (c = 1; c <= size; c++) |
175 | result += ((uint64_t)buffer[start + c - 1]) << (8 * (size - c)); | 181 | result += ((uint64_t) buffer[start + c - 1]) << (8 * (size - c)); |
176 | return result; | 182 | return result; |
177 | } | 183 | } |
178 | 184 | ||
185 | |||
179 | static float | 186 | static float |
180 | getFloat (const unsigned char *buffer, size_t start, size_t size) | 187 | getFloat (const unsigned char *buffer, size_t start, size_t size) |
181 | { | 188 | { |
@@ -194,7 +201,8 @@ getFloat (const unsigned char *buffer, size_t start, size_t size) | |||
194 | return 0.0; | 201 | return 0.0; |
195 | } | 202 | } |
196 | 203 | ||
197 | static const unsigned int MKV_Parse_list[] = { | 204 | |
205 | static const unsigned int MKV_Parse_list[] = { | ||
198 | /*Elements, containing requed information (sub-elements), see enum in mkv.h for values */ | 206 | /*Elements, containing requed information (sub-elements), see enum in mkv.h for values */ |
199 | MKVID_Segment, | 207 | MKVID_Segment, |
200 | MKVID_Info, | 208 | MKVID_Info, |
@@ -244,14 +252,14 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size, | |||
244 | if (NULL == start) | 252 | if (NULL == start) |
245 | return 0; | 253 | return 0; |
246 | p = start - data; | 254 | p = start - data; |
247 | 255 | ||
248 | /*main loop*/ | 256 | /*main loop*/ |
249 | ret = 0; | 257 | ret = 0; |
250 | do | 258 | do |
251 | { | 259 | { |
252 | offs = elementRead (data, p, size, &eID, &eSize); | 260 | offs = elementRead (data, p, size, &eID, &eSize); |
253 | p += offs; | 261 | p += offs; |
254 | if (!offs || p >= size) | 262 | if (! offs || (p >= size)) |
255 | break; | 263 | break; |
256 | if (MKVID_EBML == eID) | 264 | if (MKVID_EBML == eID) |
257 | { | 265 | { |
@@ -262,8 +270,8 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size, | |||
262 | if (! is_mkv) | 270 | if (! is_mkv) |
263 | return 0; | 271 | return 0; |
264 | for (c = 0; c < sizeof (MKV_Parse_list) / sizeof (*MKV_Parse_list); c++) | 272 | for (c = 0; c < sizeof (MKV_Parse_list) / sizeof (*MKV_Parse_list); c++) |
265 | if (MKV_Parse_list[c] == eID) | 273 | if (MKV_Parse_list[c] == eID) |
266 | break; | 274 | break; |
267 | if (c < sizeof (MKV_Parse_list) / sizeof (*MKV_Parse_list)) | 275 | if (c < sizeof (MKV_Parse_list) / sizeof (*MKV_Parse_list)) |
268 | continue; | 276 | continue; |
269 | 277 | ||
@@ -272,7 +280,7 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size, | |||
272 | 280 | ||
273 | if ( (eSize == 4) || (eSize == 8) || (eSize == 1) || (eSize == 2)) | 281 | if ( (eSize == 4) || (eSize == 8) || (eSize == 1) || (eSize == 2)) |
274 | value = getInt (data, p, eSize); | 282 | value = getInt (data, p, eSize); |
275 | 283 | ||
276 | switch (eID) | 284 | switch (eID) |
277 | { | 285 | { |
278 | case MKVID_TrackType: /*detect a stream type (video/audio/text) */ | 286 | case MKVID_TrackType: /*detect a stream type (video/audio/text) */ |
@@ -286,9 +294,9 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size, | |||
286 | have_audio = 1; | 294 | have_audio = 1; |
287 | break; | 295 | break; |
288 | case MKV_Track_subtitle: | 296 | case MKV_Track_subtitle: |
289 | break; | 297 | break; |
290 | case MKV_Track_subtitle_orig: | 298 | case MKV_Track_subtitle_orig: |
291 | break; | 299 | break; |
292 | } | 300 | } |
293 | break; | 301 | break; |
294 | case MKVID_DefaultDuration: | 302 | case MKVID_DefaultDuration: |
@@ -298,11 +306,11 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size, | |||
298 | fps = 0; | 306 | fps = 0; |
299 | break; | 307 | break; |
300 | case MKVID_Language: | 308 | case MKVID_Language: |
301 | snprintf (buffer, | 309 | snprintf (buffer, |
302 | sizeof (buffer), | 310 | sizeof (buffer), |
303 | "%.*s", | 311 | "%.*s", |
304 | (int) eSize, | 312 | (int) eSize, |
305 | data + p); | 313 | data + p); |
306 | ADD (buffer, EXTRACTOR_METATYPE_LANGUAGE); | 314 | ADD (buffer, EXTRACTOR_METATYPE_LANGUAGE); |
307 | break; | 315 | break; |
308 | case MKVID_CodecName: | 316 | case MKVID_CodecName: |
@@ -340,10 +348,10 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size, | |||
340 | if (eSize > MAX_STRING_SIZE) | 348 | if (eSize > MAX_STRING_SIZE) |
341 | break; | 349 | break; |
342 | snprintf (buffer, | 350 | snprintf (buffer, |
343 | sizeof (buffer), | 351 | sizeof (buffer), |
344 | "%.*s", | 352 | "%.*s", |
345 | (int) eSize, | 353 | (int) eSize, |
346 | (const char*) data + p); | 354 | (const char*) data + p); |
347 | ADD (buffer, EXTRACTOR_METATYPE_TITLE); | 355 | ADD (buffer, EXTRACTOR_METATYPE_TITLE); |
348 | break; | 356 | break; |
349 | default: | 357 | default: |
@@ -354,20 +362,20 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size, | |||
354 | while (1); | 362 | while (1); |
355 | 363 | ||
356 | snprintf (buffer, | 364 | snprintf (buffer, |
357 | sizeof (buffer), | 365 | sizeof (buffer), |
358 | "%u s (%s%s%s)", | 366 | "%u s (%s%s%s)", |
359 | (unsigned int) (duration / 1e+9 * (float) timescale), | 367 | (unsigned int) (duration / 1e+9 * (float) timescale), |
360 | (have_audio ? "audio" : ""), | 368 | (have_audio ? "audio" : ""), |
361 | ((have_audio && have_video) ? "/" : ""), | 369 | ((have_audio && have_video) ? "/" : ""), |
362 | (have_video ? "video" : "")); | 370 | (have_video ? "video" : "")); |
363 | if ( (have_audio || have_video) && (duration >= 0.0) ) | 371 | if ( (have_audio || have_video) && (duration >= 0.0) ) |
364 | ADD (buffer, EXTRACTOR_METATYPE_DURATION); | 372 | ADD (buffer, EXTRACTOR_METATYPE_DURATION); |
365 | if ( (value_width != 0) && (value_height != 0) ) | 373 | if ( (value_width != 0) && (value_height != 0) ) |
366 | { | 374 | { |
367 | snprintf (buffer, | 375 | snprintf (buffer, |
368 | sizeof(buffer), | 376 | sizeof(buffer), |
369 | "%ux%u", | 377 | "%ux%u", |
370 | value_width, value_height); | 378 | value_width, value_height); |
371 | ADD (buffer, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); | 379 | ADD (buffer, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); |
372 | } | 380 | } |
373 | 381 | ||
@@ -375,34 +383,34 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size, | |||
375 | { | 383 | { |
376 | if ( (fps != 0) && (bit_depth != 0) ) | 384 | if ( (fps != 0) && (bit_depth != 0) ) |
377 | snprintf (buffer, | 385 | snprintf (buffer, |
378 | sizeof (buffer), | 386 | sizeof (buffer), |
379 | "%.*s (%u fps, %u bit)", | 387 | "%.*s (%u fps, %u bit)", |
380 | codec_strlen, | 388 | codec_strlen, |
381 | codec, | 389 | codec, |
382 | fps, | 390 | fps, |
383 | bit_depth); | 391 | bit_depth); |
384 | else if (fps != 0) | 392 | else if (fps != 0) |
385 | snprintf (buffer, | 393 | snprintf (buffer, |
386 | sizeof (buffer), | 394 | sizeof (buffer), |
387 | "%.*s (%u fps)", | 395 | "%.*s (%u fps)", |
388 | codec_strlen, | 396 | codec_strlen, |
389 | codec, | 397 | codec, |
390 | fps); | 398 | fps); |
391 | else if (bit_depth != 0) | 399 | else if (bit_depth != 0) |
392 | snprintf (buffer, | 400 | snprintf (buffer, |
393 | sizeof (buffer), | 401 | sizeof (buffer), |
394 | "%.*s (%u bit)", | 402 | "%.*s (%u bit)", |
395 | codec_strlen, | 403 | codec_strlen, |
396 | codec, | 404 | codec, |
397 | bit_depth); | 405 | bit_depth); |
398 | else | 406 | else |
399 | snprintf (buffer, | 407 | snprintf (buffer, |
400 | sizeof (buffer), | 408 | sizeof (buffer), |
401 | "%.*s", | 409 | "%.*s", |
402 | codec_strlen, | 410 | codec_strlen, |
403 | codec); | 411 | codec); |
404 | ADD (buffer, | 412 | ADD (buffer, |
405 | EXTRACTOR_METATYPE_FORMAT); | 413 | EXTRACTOR_METATYPE_FORMAT); |
406 | } | 414 | } |
407 | EXIT: | 415 | EXIT: |
408 | return ret; | 416 | return ret; |
diff --git a/src/plugins/old/mp3_extractor.c b/src/plugins/old/mp3_extractor.c index 99afd15..076b427 100644 --- a/src/plugins/old/mp3_extractor.c +++ b/src/plugins/old/mp3_extractor.c | |||
@@ -91,21 +91,21 @@ static const int freq_table[4][3] = { | |||
91 | {48000, 24000, 12000}, | 91 | {48000, 24000, 12000}, |
92 | {32000, 16000, 8000} | 92 | {32000, 16000, 8000} |
93 | }; | 93 | }; |
94 | static const char * const channel_modes[4] = { | 94 | static const char *const channel_modes[4] = { |
95 | gettext_noop("stereo"), | 95 | gettext_noop ("stereo"), |
96 | gettext_noop("joint stereo"), | 96 | gettext_noop ("joint stereo"), |
97 | gettext_noop("dual channel"), | 97 | gettext_noop ("dual channel"), |
98 | gettext_noop("mono") | 98 | gettext_noop ("mono") |
99 | }; | 99 | }; |
100 | static const char * const mpeg_versions[3] = { | 100 | static const char *const mpeg_versions[3] = { |
101 | gettext_noop("MPEG-1"), | 101 | gettext_noop ("MPEG-1"), |
102 | gettext_noop("MPEG-2"), | 102 | gettext_noop ("MPEG-2"), |
103 | gettext_noop("MPEG-2.5") | 103 | gettext_noop ("MPEG-2.5") |
104 | }; | 104 | }; |
105 | static const char * const layer_names[3] = { | 105 | static const char *const layer_names[3] = { |
106 | gettext_noop("Layer I"), | 106 | gettext_noop ("Layer I"), |
107 | gettext_noop("Layer II"), | 107 | gettext_noop ("Layer II"), |
108 | gettext_noop("Layer III") | 108 | gettext_noop ("Layer III") |
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
@@ -113,7 +113,10 @@ static const char * const layer_names[3] = { | |||
113 | #define SYSERR 1 | 113 | #define SYSERR 1 |
114 | #define INVALID_ID3 2 | 114 | #define INVALID_ID3 2 |
115 | 115 | ||
116 | #define ADDR(s,t) do { if (0 != proc (proc_cls, "mp3", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) | 116 | #define ADDR(s,t) do { if (0 != proc (proc_cls, "mp3", t, \ |
117 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", \ | ||
118 | s, strlen (s) + 1)) return 1; \ | ||
119 | } while (0) | ||
117 | 120 | ||
118 | struct mp3_state | 121 | struct mp3_state |
119 | { | 122 | { |
@@ -163,6 +166,7 @@ EXTRACTOR_mp3_init_state_method () | |||
163 | return state; | 166 | return state; |
164 | } | 167 | } |
165 | 168 | ||
169 | |||
166 | static int | 170 | static int |
167 | EXTRACTOR_mp3_discard_state_method (struct mp3_state *state) | 171 | EXTRACTOR_mp3_discard_state_method (struct mp3_state *state) |
168 | { | 172 | { |
@@ -173,51 +177,58 @@ EXTRACTOR_mp3_discard_state_method (struct mp3_state *state) | |||
173 | return 1; | 177 | return 1; |
174 | } | 178 | } |
175 | 179 | ||
180 | |||
176 | static int | 181 | static int |
177 | calculate_frame_statistics_and_maybe_report_it (struct EXTRACTOR_PluginList *plugin, | 182 | calculate_frame_statistics_and_maybe_report_it (struct |
178 | struct mp3_state *state, EXTRACTOR_MetaDataProcessor proc, void *proc_cls) | 183 | EXTRACTOR_PluginList *plugin, |
184 | struct mp3_state *state, | ||
185 | EXTRACTOR_MetaDataProcessor proc, | ||
186 | void *proc_cls) | ||
179 | { | 187 | { |
180 | int length; | 188 | int length; |
181 | char format[512]; | 189 | char format[512]; |
182 | 190 | ||
183 | if (((double) state->number_of_valid_frames / (double) state->number_of_frames) < 0.8 || | 191 | if ((((double) state->number_of_valid_frames |
184 | state->number_of_valid_frames <= 2) | 192 | / (double) state->number_of_frames) < 0.8) || |
193 | (state->number_of_valid_frames <= 2) ) | ||
185 | /* Unlikely to be an mp3 file */ | 194 | /* Unlikely to be an mp3 file */ |
186 | return 0; | 195 | return 0; |
187 | ADDR ("audio/mpeg", EXTRACTOR_METATYPE_MIMETYPE); | 196 | ADDR ("audio/mpeg", EXTRACTOR_METATYPE_MIMETYPE); |
188 | state->avg_bps = state->avg_bps / state->number_of_valid_frames; | 197 | state->avg_bps = state->avg_bps / state->number_of_valid_frames; |
189 | if (state->sample_rate > 0) | 198 | if (state->sample_rate > 0) |
190 | length = 1152 * state->number_of_valid_frames / state->sample_rate; | 199 | length = 1152 * state->number_of_valid_frames / state->sample_rate; |
191 | else if (state->avg_bps > 0 || state->bitrate > 0) | 200 | else if ((state->avg_bps > 0) || (state->bitrate > 0)) |
192 | length = plugin->fsize / (state->avg_bps ? state->avg_bps : state->bitrate ? state->bitrate : 1) / 125; | 201 | length = plugin->fsize / (state->avg_bps ? state->avg_bps : state->bitrate ? |
202 | state->bitrate : 1) / 125; | ||
193 | else | 203 | else |
194 | length = 0; | 204 | length = 0; |
195 | 205 | ||
196 | ADDR (mpeg_versions[state->mpeg_ver - 1], EXTRACTOR_METATYPE_FORMAT_VERSION); | 206 | ADDR (mpeg_versions[state->mpeg_ver - 1], EXTRACTOR_METATYPE_FORMAT_VERSION); |
197 | snprintf (format, | 207 | snprintf (format, |
198 | sizeof (format), | 208 | sizeof (format), |
199 | "%s %s audio, %d kbps (%s), %d Hz, %s, %s, %s", | 209 | "%s %s audio, %d kbps (%s), %d Hz, %s, %s, %s", |
200 | mpeg_versions[state->mpeg_ver - 1], | 210 | mpeg_versions[state->mpeg_ver - 1], |
201 | layer_names[state->layer - 1], | 211 | layer_names[state->layer - 1], |
202 | state->avg_bps, | 212 | state->avg_bps, |
203 | state->vbr_flag ? _("VBR") : _("CBR"), | 213 | state->vbr_flag ? _ ("VBR") : _ ("CBR"), |
204 | state->sample_rate, | 214 | state->sample_rate, |
205 | channel_modes[state->ch], | 215 | channel_modes[state->ch], |
206 | state->copyright_flag ? _("copyright") : _("no copyright"), | 216 | state->copyright_flag ? _ ("copyright") : _ ("no copyright"), |
207 | state->original_flag ? _("original") : _("copy") ); | 217 | state->original_flag ? _ ("original") : _ ("copy") ); |
208 | 218 | ||
209 | ADDR (format, EXTRACTOR_METATYPE_RESOURCE_TYPE); | 219 | ADDR (format, EXTRACTOR_METATYPE_RESOURCE_TYPE); |
210 | snprintf (format, | 220 | snprintf (format, |
211 | sizeof (format), "%dm%02d", | 221 | sizeof (format), "%dm%02d", |
212 | length / 60, length % 60); | 222 | length / 60, length % 60); |
213 | ADDR (format, EXTRACTOR_METATYPE_DURATION); | 223 | ADDR (format, EXTRACTOR_METATYPE_DURATION); |
214 | return 0; | 224 | return 0; |
215 | } | 225 | } |
216 | 226 | ||
227 | |||
217 | int | 228 | int |
218 | EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, | 229 | EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, |
219 | EXTRACTOR_MetaDataProcessor proc, | 230 | EXTRACTOR_MetaDataProcessor proc, |
220 | void *proc_cls) | 231 | void *proc_cls) |
221 | { | 232 | { |
222 | int64_t offset = 0; | 233 | int64_t offset = 0; |
223 | int64_t round_offset; | 234 | int64_t round_offset; |
@@ -255,24 +266,29 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, | |||
255 | while (1) | 266 | while (1) |
256 | { | 267 | { |
257 | pl_seek (plugin, offset, SEEK_SET); | 268 | pl_seek (plugin, offset, SEEK_SET); |
258 | read_result = pl_read (plugin, &data, 1024*1024); | 269 | read_result = pl_read (plugin, &data, 1024 * 1024); |
259 | if (read_result < 4) | 270 | if (read_result < 4) |
260 | { | 271 | { |
261 | calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, proc_cls); | 272 | calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, |
273 | proc_cls); | ||
262 | return EXTRACTOR_mp3_discard_state_method (state); | 274 | return EXTRACTOR_mp3_discard_state_method (state); |
263 | } | 275 | } |
264 | for (i = 0; i + 3 < read_result; i++) | 276 | for (i = 0; i + 3 < read_result; i++) |
265 | if (((*((uint32_t *) &data[i])) & MPA_SYNC_MASK_MEM) == MPA_SYNC_MASK_MEM) | 277 | if (((*((uint32_t *) &data[i])) & MPA_SYNC_MASK_MEM) == |
278 | MPA_SYNC_MASK_MEM) | ||
266 | break; | 279 | break; |
267 | if (i + 3 >= 1024*1024) | 280 | if (i + 3 >= 1024 * 1024) |
268 | offset += read_result - 3; | 281 | offset += read_result - 3; |
269 | else | 282 | else |
270 | break; | 283 | break; |
271 | if (offset > round_offset + 31*1024*1024) | 284 | if (offset > round_offset + 31 * 1024 * 1024) |
272 | { | 285 | { |
273 | if (((state->number_of_valid_frames > 2) && ((double) state->number_of_valid_frames / (double) state->number_of_frames) < 0.8)) | 286 | if (((state->number_of_valid_frames > 2) && |
287 | ( ((double) state->number_of_valid_frames | ||
288 | / (double) state->number_of_frames) < 0.8) )) | ||
274 | { | 289 | { |
275 | calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, proc_cls); | 290 | calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, |
291 | proc_cls); | ||
276 | } | 292 | } |
277 | return EXTRACTOR_mp3_discard_state_method (state); | 293 | return EXTRACTOR_mp3_discard_state_method (state); |
278 | } | 294 | } |
@@ -280,11 +296,12 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, | |||
280 | pl_seek (plugin, offset + i, SEEK_SET); | 296 | pl_seek (plugin, offset + i, SEEK_SET); |
281 | if (4 != pl_read (plugin, &data, 4)) | 297 | if (4 != pl_read (plugin, &data, 4)) |
282 | { | 298 | { |
283 | calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, proc_cls); | 299 | calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, |
300 | proc_cls); | ||
284 | return EXTRACTOR_mp3_discard_state_method (state); | 301 | return EXTRACTOR_mp3_discard_state_method (state); |
285 | } | 302 | } |
286 | state->header = (data[0] << 24) | (data[1] << 16) | | 303 | state->header = (data[0] << 24) | (data[1] << 16) |
287 | (data[2] << 8) | data[3]; | 304 | | (data[2] << 8) | data[3]; |
288 | if ((state->header & MPA_SYNC_MASK) == MPA_SYNC_MASK) | 305 | if ((state->header & MPA_SYNC_MASK) == MPA_SYNC_MASK) |
289 | { | 306 | { |
290 | state->state = MP3_READING_FRAME; | 307 | state->state = MP3_READING_FRAME; |
@@ -336,8 +353,8 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, | |||
336 | idx_num = (mpeg_ver - 1) * 3 + layer - 1; | 353 | idx_num = (mpeg_ver - 1) * 3 + layer - 1; |
337 | else | 354 | else |
338 | idx_num = 2 + layer; | 355 | idx_num = 2 + layer; |
339 | bitrate = 1000 * bitrate_table[(state->header >> MPA_BITRATE_SHIFT) & | 356 | bitrate = 1000 * bitrate_table[(state->header >> MPA_BITRATE_SHIFT) |
340 | MPA_BITRATE_MASK][idx_num]; | 357 | & MPA_BITRATE_MASK][idx_num]; |
341 | if (bitrate < 0) | 358 | if (bitrate < 0) |
342 | { | 359 | { |
343 | /*error in header */ | 360 | /*error in header */ |
@@ -345,8 +362,8 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, | |||
345 | offset += 1; | 362 | offset += 1; |
346 | break; | 363 | break; |
347 | } | 364 | } |
348 | sample_rate = freq_table[(state->header >> MPA_FREQ_SHIFT) & | 365 | sample_rate = freq_table[(state->header >> MPA_FREQ_SHIFT) |
349 | MPA_FREQ_MASK][mpeg_ver - 1]; | 366 | & MPA_FREQ_MASK][mpeg_ver - 1]; |
350 | if (sample_rate <= 0) | 367 | if (sample_rate <= 0) |
351 | { | 368 | { |
352 | /*error in header */ | 369 | /*error in header */ |
@@ -358,9 +375,13 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, | |||
358 | copyright_flag = (state->header >> MPA_COPYRIGHT_SHIFT) & 0x1; | 375 | copyright_flag = (state->header >> MPA_COPYRIGHT_SHIFT) & 0x1; |
359 | original_flag = (state->header >> MPA_ORIGINAL_SHIFT) & 0x1; | 376 | original_flag = (state->header >> MPA_ORIGINAL_SHIFT) & 0x1; |
360 | if (layer == LAYER_1) | 377 | if (layer == LAYER_1) |
361 | frame_size = (12 * bitrate / sample_rate + ((state->header >> MPA_PADDING_SHIFT) & 0x1)) * 4; | 378 | frame_size = (12 * bitrate / sample_rate + ((state->header |
379 | >> MPA_PADDING_SHIFT) | ||
380 | & 0x1)) * 4; | ||
362 | else | 381 | else |
363 | frame_size = 144 * bitrate / sample_rate + ((state->header >> MPA_PADDING_SHIFT) & 0x1); | 382 | frame_size = 144 * bitrate / sample_rate + ((state->header |
383 | >> MPA_PADDING_SHIFT) | ||
384 | & 0x1); | ||
364 | if (frame_size < 8) | 385 | if (frame_size < 8) |
365 | { | 386 | { |
366 | /*error in header */ | 387 | /*error in header */ |
@@ -390,4 +411,5 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, | |||
390 | return 1; | 411 | return 1; |
391 | } | 412 | } |
392 | 413 | ||
414 | |||
393 | /* end of mp3_extractor.c */ | 415 | /* end of mp3_extractor.c */ |
diff --git a/src/plugins/old/pack.c b/src/plugins/old/pack.c index 968cf67..4f9e19d 100644 --- a/src/plugins/old/pack.c +++ b/src/plugins/old/pack.c | |||
@@ -27,7 +27,7 @@ MODIFICATIONS. | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "pack.h" | 28 | #include "pack.h" |
29 | 29 | ||
30 | #if !(defined(_WIN32) && defined(cbNDRContext)) | 30 | #if ! (defined(_WIN32) && defined(cbNDRContext)) |
31 | typedef unsigned char byte; | 31 | typedef unsigned char byte; |
32 | #endif | 32 | #endif |
33 | typedef unsigned short half; | 33 | typedef unsigned short half; |
@@ -37,11 +37,10 @@ typedef signed short shalf; | |||
37 | typedef signed int sword; | 37 | typedef signed int sword; |
38 | 38 | ||
39 | 39 | ||
40 | |||
41 | int | 40 | int |
42 | EXTRACTOR_common_cat_unpack (const void *buf, | 41 | EXTRACTOR_common_cat_unpack (const void *buf, |
43 | const char *fmt, | 42 | const char *fmt, |
44 | ...) | 43 | ...) |
45 | { | 44 | { |
46 | va_list ap; | 45 | va_list ap; |
47 | word maxlen, len, *wordp; | 46 | word maxlen, len, *wordp; |
@@ -63,283 +62,282 @@ EXTRACTOR_common_cat_unpack (const void *buf, | |||
63 | va_start (ap, fmt); | 62 | va_start (ap, fmt); |
64 | 63 | ||
65 | while (*fmt) | 64 | while (*fmt) |
65 | { | ||
66 | nreps = 1; | ||
67 | |||
68 | if (isdigit ( (unsigned char) *fmt)) | ||
66 | { | 69 | { |
67 | nreps = 1; | 70 | /* We use cp instead of format to keep the 'const' qualifier of fmt */ |
71 | nreps = strtoul (fmt, &cp, 0); | ||
72 | fmt = cp; | ||
73 | if (*fmt == 'a') | ||
74 | isnonprefixed = 0; | ||
75 | } | ||
68 | 76 | ||
69 | if (isdigit ( (unsigned char) *fmt)) | 77 | switch (*fmt) |
78 | { | ||
79 | case 'B': | ||
80 | case 'b': | ||
81 | bytep = va_arg (ap, byte *); | ||
82 | for (i = 0; i < nreps; ++i) | ||
83 | { | ||
84 | *bytep = *bp++; | ||
85 | ++bytep; | ||
86 | npacked += 1; | ||
87 | } | ||
88 | break; | ||
89 | |||
90 | |||
91 | case 'h': | ||
92 | halfp = va_arg (ap, half *); | ||
93 | for (i = 0; i < nreps; ++i) | ||
94 | { | ||
95 | *halfp = *bp++; | ||
96 | *halfp |= *bp++ << 8; | ||
97 | ++halfp; | ||
98 | npacked += 2; | ||
99 | } | ||
100 | break; | ||
101 | |||
102 | case 'H': | ||
103 | halfp = va_arg (ap, half *); | ||
104 | for (i = 0; i < nreps; ++i) | ||
105 | { | ||
106 | *halfp = *bp++ << 8; | ||
107 | *halfp |= *bp++; | ||
108 | ++halfp; | ||
109 | npacked += 2; | ||
110 | } | ||
111 | break; | ||
112 | |||
113 | |||
114 | case 'w': | ||
115 | wordp = va_arg (ap, word *); | ||
116 | for (i = 0; i < nreps; ++i) | ||
117 | { | ||
118 | *wordp = *bp++; | ||
119 | *wordp |= *bp++ << 8; | ||
120 | *wordp |= *bp++ << 16; | ||
121 | *wordp |= *bp++ << 24; | ||
122 | ++wordp; | ||
123 | npacked += 4; | ||
124 | } | ||
125 | break; | ||
126 | |||
127 | case 'x': | ||
128 | ll = va_arg (ap, long long *); | ||
129 | for (i = 0; i < nreps; ++i) | ||
130 | { | ||
131 | *ll = ((long long) *bp++); | ||
132 | *ll |= ((long long) *bp++) << 8; | ||
133 | *ll |= ((long long) *bp++) << 16; | ||
134 | *ll |= ((long long) *bp++) << 24; | ||
135 | *ll |= ((long long) *bp++) << 32; | ||
136 | *ll |= ((long long) *bp++) << 40; | ||
137 | *ll |= ((long long) *bp++) << 48; | ||
138 | *ll |= ((long long) *bp++) << 56; | ||
139 | ++ll; | ||
140 | npacked += 8; | ||
141 | } | ||
142 | break; | ||
143 | |||
144 | case 'W': | ||
145 | wordp = va_arg (ap, word *); | ||
146 | for (i = 0; i < nreps; ++i) | ||
147 | { | ||
148 | *wordp = *bp++ << 24; | ||
149 | *wordp |= *bp++ << 16; | ||
150 | *wordp |= *bp++ << 8; | ||
151 | *wordp |= *bp++; | ||
152 | ++wordp; | ||
153 | npacked += 4; | ||
154 | } | ||
155 | break; | ||
156 | |||
157 | case 'X': | ||
158 | ll = va_arg (ap, long long *); | ||
159 | for (i = 0; i < nreps; ++i) | ||
160 | { | ||
161 | *ll = ((long long) *bp++) << 56; | ||
162 | *ll |= ((long long) *bp++) << 48; | ||
163 | *ll |= ((long long) *bp++) << 40; | ||
164 | *ll |= ((long long) *bp++) << 32; | ||
165 | *ll |= ((long long) *bp++) << 24; | ||
166 | *ll |= ((long long) *bp++) << 18; | ||
167 | *ll |= ((long long) *bp++) << 8; | ||
168 | *ll |= ((long long) *bp++); | ||
169 | ++ll; | ||
170 | npacked += 8; | ||
171 | } | ||
172 | break; | ||
173 | |||
174 | |||
175 | case 'A': | ||
176 | if (isnonprefixed) | ||
177 | { | ||
178 | maxlen = va_arg (ap, word); | ||
179 | arr = va_arg (ap, void *); | ||
180 | |||
181 | len = *bp++ << 24; | ||
182 | len |= *bp++ << 16; | ||
183 | len |= *bp++ << 8; | ||
184 | len |= *bp++; | ||
185 | |||
186 | if (len > maxlen) | ||
70 | { | 187 | { |
71 | /* We use cp instead of format to keep the 'const' qualifier of fmt */ | 188 | va_end (ap); |
72 | nreps = strtoul (fmt, &cp, 0); | 189 | return -1; |
73 | fmt = cp; | ||
74 | if (*fmt == 'a') | ||
75 | isnonprefixed = 0; | ||
76 | } | 190 | } |
77 | 191 | ||
78 | switch (*fmt) | 192 | memmove (arr, bp, len); |
193 | bp += len; | ||
194 | |||
195 | npacked += len; | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | cbvp = va_arg (ap, struct cat_bvec *); | ||
200 | for (i = 0; i < nreps; ++i) | ||
201 | { | ||
202 | maxlen = cbvp->len; | ||
203 | arr = cbvp->data; | ||
204 | |||
205 | len = *bp++ << 24; | ||
206 | len |= *bp++ << 16; | ||
207 | len |= *bp++ << 8; | ||
208 | len |= *bp++; | ||
209 | |||
210 | if (len > maxlen) | ||
211 | return -1; | ||
212 | |||
213 | memmove (arr, bp, len); | ||
214 | cbvp->len = len; | ||
215 | bp += len; | ||
216 | |||
217 | ++cbvp; | ||
218 | npacked += len; | ||
219 | } | ||
220 | isnonprefixed = 1; | ||
221 | } | ||
222 | break; | ||
223 | |||
224 | case 'C': | ||
225 | case 'c': | ||
226 | sbytep = va_arg (ap, sbyte *); | ||
227 | for (i = 0; i < nreps; ++i) | ||
228 | { | ||
229 | *sbytep = *bp++; | ||
230 | |||
231 | if ((sizeof (sbyte) > 1) && (*sbytep & 0x80)) | ||
232 | *sbytep |= (~0) << ((sizeof (sbyte) - 1) * 8); | ||
233 | |||
234 | ++sbytep; | ||
235 | npacked += 1; | ||
236 | } | ||
237 | break; | ||
238 | |||
239 | |||
240 | case 's': | ||
241 | shalfp = va_arg (ap, shalf *); | ||
242 | for (i = 0; i < nreps; ++i) | ||
243 | { | ||
244 | *shalfp = *bp++; | ||
245 | *shalfp |= *bp++ << 8; | ||
246 | |||
247 | if ((sizeof (shalf) > 2) && (*shalfp & 0x8000)) | ||
248 | *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8); | ||
249 | |||
250 | ++shalfp; | ||
251 | npacked += 2; | ||
252 | } | ||
253 | break; | ||
254 | |||
255 | case 'S': | ||
256 | shalfp = va_arg (ap, shalf *); | ||
257 | for (i = 0; i < nreps; ++i) | ||
258 | { | ||
259 | *shalfp = *bp++ << 8; | ||
260 | *shalfp |= *bp++; | ||
261 | |||
262 | if ((sizeof (shalf) > 2) && (*shalfp & 0x8000)) | ||
263 | *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8); | ||
264 | |||
265 | ++shalfp; | ||
266 | npacked += 2; | ||
267 | } | ||
268 | break; | ||
269 | |||
270 | case 'l': | ||
271 | swordp = va_arg (ap, sword *); | ||
272 | for (i = 0; i < nreps; ++i) | ||
273 | { | ||
274 | *swordp = *bp++; | ||
275 | *swordp |= *bp++ << 8; | ||
276 | *swordp |= *bp++ << 16; | ||
277 | *swordp |= *bp++ << 24; | ||
278 | |||
279 | if ((sizeof (swordp) > 4) && (*swordp & 0x80000000)) | ||
280 | *swordp |= (~0) << ((sizeof (sword) - 4) * 8); | ||
281 | |||
282 | ++swordp; | ||
283 | npacked += 4; | ||
284 | } | ||
285 | break; | ||
286 | |||
287 | case 'L': | ||
288 | swordp = va_arg (ap, sword *); | ||
289 | for (i = 0; i < nreps; ++i) | ||
290 | { | ||
291 | *swordp = *bp++ << 24; | ||
292 | *swordp |= *bp++ << 16; | ||
293 | *swordp |= *bp++ << 8; | ||
294 | *swordp |= *bp++; | ||
295 | |||
296 | if ((sizeof (swordp) > 4) && (*swordp & 0x80000000)) | ||
297 | *swordp |= (~0) << ((sizeof (sword) - 4) * 8); | ||
298 | |||
299 | ++swordp; | ||
300 | npacked += 4; | ||
301 | } | ||
302 | break; | ||
303 | |||
304 | case 'P': | ||
305 | cbvp = va_arg (ap, struct cat_bvec *); | ||
306 | for (i = 0; i < nreps; ++i) | ||
307 | { | ||
308 | len = *bp++ << 24; | ||
309 | len |= *bp++ << 16; | ||
310 | len |= *bp++ << 8; | ||
311 | len |= *bp++; | ||
312 | |||
313 | newbuf = (byte *) malloc (len); | ||
314 | |||
315 | if (! newbuf) | ||
79 | { | 316 | { |
80 | case 'B': | 317 | int j; |
81 | case 'b': | 318 | for (j = 0; j < i; j++) |
82 | bytep = va_arg (ap, byte *); | 319 | free (cbvp[i].data); |
83 | for (i = 0; i < nreps; ++i) | ||
84 | { | ||
85 | *bytep = *bp++; | ||
86 | ++bytep; | ||
87 | npacked += 1; | ||
88 | } | ||
89 | break; | ||
90 | |||
91 | |||
92 | |||
93 | case 'h': | ||
94 | halfp = va_arg (ap, half *); | ||
95 | for (i = 0; i < nreps; ++i) | ||
96 | { | ||
97 | *halfp = *bp++; | ||
98 | *halfp |= *bp++ << 8; | ||
99 | ++halfp; | ||
100 | npacked += 2; | ||
101 | } | ||
102 | break; | ||
103 | |||
104 | case 'H': | ||
105 | halfp = va_arg (ap, half *); | ||
106 | for (i = 0; i < nreps; ++i) | ||
107 | { | ||
108 | *halfp = *bp++ << 8; | ||
109 | *halfp |= *bp++; | ||
110 | ++halfp; | ||
111 | npacked += 2; | ||
112 | } | ||
113 | break; | ||
114 | |||
115 | |||
116 | case 'w': | ||
117 | wordp = va_arg (ap, word *); | ||
118 | for (i = 0; i < nreps; ++i) | ||
119 | { | ||
120 | *wordp = *bp++; | ||
121 | *wordp |= *bp++ << 8; | ||
122 | *wordp |= *bp++ << 16; | ||
123 | *wordp |= *bp++ << 24; | ||
124 | ++wordp; | ||
125 | npacked += 4; | ||
126 | } | ||
127 | break; | ||
128 | |||
129 | case 'x': | ||
130 | ll = va_arg (ap, long long *); | ||
131 | for (i = 0; i < nreps; ++i) | ||
132 | { | ||
133 | *ll = ((long long) *bp++); | ||
134 | *ll |= ((long long) *bp++) << 8; | ||
135 | *ll |= ((long long) *bp++) << 16; | ||
136 | *ll |= ((long long) *bp++) << 24; | ||
137 | *ll |= ((long long) *bp++) << 32; | ||
138 | *ll |= ((long long) *bp++) << 40; | ||
139 | *ll |= ((long long) *bp++) << 48; | ||
140 | *ll |= ((long long) *bp++) << 56; | ||
141 | ++ll; | ||
142 | npacked += 8; | ||
143 | } | ||
144 | break; | ||
145 | |||
146 | case 'W': | ||
147 | wordp = va_arg (ap, word *); | ||
148 | for (i = 0; i < nreps; ++i) | ||
149 | { | ||
150 | *wordp = *bp++ << 24; | ||
151 | *wordp |= *bp++ << 16; | ||
152 | *wordp |= *bp++ << 8; | ||
153 | *wordp |= *bp++; | ||
154 | ++wordp; | ||
155 | npacked += 4; | ||
156 | } | ||
157 | break; | ||
158 | |||
159 | case 'X': | ||
160 | ll = va_arg (ap, long long *); | ||
161 | for (i = 0; i < nreps; ++i) | ||
162 | { | ||
163 | *ll = ((long long) *bp++) << 56; | ||
164 | *ll |= ((long long) *bp++) << 48; | ||
165 | *ll |= ((long long) *bp++) << 40; | ||
166 | *ll |= ((long long) *bp++) << 32; | ||
167 | *ll |= ((long long) *bp++) << 24; | ||
168 | *ll |= ((long long) *bp++) << 18; | ||
169 | *ll |= ((long long) *bp++) << 8; | ||
170 | *ll |= ((long long) *bp++); | ||
171 | ++ll; | ||
172 | npacked += 8; | ||
173 | } | ||
174 | break; | ||
175 | |||
176 | |||
177 | case 'A': | ||
178 | if (isnonprefixed) | ||
179 | { | ||
180 | maxlen = va_arg (ap, word); | ||
181 | arr = va_arg (ap, void *); | ||
182 | |||
183 | len = *bp++ << 24; | ||
184 | len |= *bp++ << 16; | ||
185 | len |= *bp++ << 8; | ||
186 | len |= *bp++; | ||
187 | |||
188 | if (len > maxlen) | ||
189 | { | ||
190 | va_end (ap); | ||
191 | return -1; | ||
192 | } | ||
193 | |||
194 | memmove (arr, bp, len); | ||
195 | bp += len; | ||
196 | |||
197 | npacked += len; | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | cbvp = va_arg (ap, struct cat_bvec *); | ||
202 | for (i = 0; i < nreps; ++i) | ||
203 | { | ||
204 | maxlen = cbvp->len; | ||
205 | arr = cbvp->data; | ||
206 | |||
207 | len = *bp++ << 24; | ||
208 | len |= *bp++ << 16; | ||
209 | len |= *bp++ << 8; | ||
210 | len |= *bp++; | ||
211 | |||
212 | if (len > maxlen) | ||
213 | return -1; | ||
214 | |||
215 | memmove (arr, bp, len); | ||
216 | cbvp->len = len; | ||
217 | bp += len; | ||
218 | |||
219 | ++cbvp; | ||
220 | npacked += len; | ||
221 | } | ||
222 | isnonprefixed = 1; | ||
223 | } | ||
224 | break; | ||
225 | |||
226 | case 'C': | ||
227 | case 'c': | ||
228 | sbytep = va_arg (ap, sbyte *); | ||
229 | for (i = 0; i < nreps; ++i) | ||
230 | { | ||
231 | *sbytep = *bp++; | ||
232 | |||
233 | if ((sizeof (sbyte) > 1) && (*sbytep & 0x80)) | ||
234 | *sbytep |= (~0) << ((sizeof (sbyte) - 1) * 8); | ||
235 | |||
236 | ++sbytep; | ||
237 | npacked += 1; | ||
238 | } | ||
239 | break; | ||
240 | |||
241 | |||
242 | case 's': | ||
243 | shalfp = va_arg (ap, shalf *); | ||
244 | for (i = 0; i < nreps; ++i) | ||
245 | { | ||
246 | *shalfp = *bp++; | ||
247 | *shalfp |= *bp++ << 8; | ||
248 | |||
249 | if ((sizeof (shalf) > 2) && (*shalfp & 0x8000)) | ||
250 | *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8); | ||
251 | |||
252 | ++shalfp; | ||
253 | npacked += 2; | ||
254 | } | ||
255 | break; | ||
256 | |||
257 | case 'S': | ||
258 | shalfp = va_arg (ap, shalf *); | ||
259 | for (i = 0; i < nreps; ++i) | ||
260 | { | ||
261 | *shalfp = *bp++ << 8; | ||
262 | *shalfp |= *bp++; | ||
263 | |||
264 | if ((sizeof (shalf) > 2) && (*shalfp & 0x8000)) | ||
265 | *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8); | ||
266 | |||
267 | ++shalfp; | ||
268 | npacked += 2; | ||
269 | } | ||
270 | break; | ||
271 | |||
272 | case 'l': | ||
273 | swordp = va_arg (ap, sword *); | ||
274 | for (i = 0; i < nreps; ++i) | ||
275 | { | ||
276 | *swordp = *bp++; | ||
277 | *swordp |= *bp++ << 8; | ||
278 | *swordp |= *bp++ << 16; | ||
279 | *swordp |= *bp++ << 24; | ||
280 | |||
281 | if ((sizeof (swordp) > 4) && (*swordp & 0x80000000)) | ||
282 | *swordp |= (~0) << ((sizeof (sword) - 4) * 8); | ||
283 | |||
284 | ++swordp; | ||
285 | npacked += 4; | ||
286 | } | ||
287 | break; | ||
288 | |||
289 | case 'L': | ||
290 | swordp = va_arg (ap, sword *); | ||
291 | for (i = 0; i < nreps; ++i) | ||
292 | { | ||
293 | *swordp = *bp++ << 24; | ||
294 | *swordp |= *bp++ << 16; | ||
295 | *swordp |= *bp++ << 8; | ||
296 | *swordp |= *bp++; | ||
297 | |||
298 | if ((sizeof (swordp) > 4) && (*swordp & 0x80000000)) | ||
299 | *swordp |= (~0) << ((sizeof (sword) - 4) * 8); | ||
300 | |||
301 | ++swordp; | ||
302 | npacked += 4; | ||
303 | } | ||
304 | break; | ||
305 | |||
306 | case 'P': | ||
307 | cbvp = va_arg (ap, struct cat_bvec *); | ||
308 | for (i = 0; i < nreps; ++i) | ||
309 | { | ||
310 | len = *bp++ << 24; | ||
311 | len |= *bp++ << 16; | ||
312 | len |= *bp++ << 8; | ||
313 | len |= *bp++; | ||
314 | |||
315 | newbuf = (byte *) malloc (len); | ||
316 | |||
317 | if (!newbuf) | ||
318 | { | ||
319 | int j; | ||
320 | for (j = 0; j < i; j++) | ||
321 | free (cbvp[i].data); | ||
322 | va_end (ap); | ||
323 | return -1; | ||
324 | } | ||
325 | |||
326 | memmove (newbuf, bp, len); | ||
327 | cbvp[i].data = newbuf; | ||
328 | cbvp[i].len = len; | ||
329 | |||
330 | bp += len; | ||
331 | npacked += len; | ||
332 | } | ||
333 | break; | ||
334 | |||
335 | default: | ||
336 | va_end (ap); | 320 | va_end (ap); |
337 | return -1; | 321 | return -1; |
338 | } | 322 | } |
339 | 323 | ||
340 | ++fmt; | 324 | memmove (newbuf, bp, len); |
325 | cbvp[i].data = newbuf; | ||
326 | cbvp[i].len = len; | ||
327 | |||
328 | bp += len; | ||
329 | npacked += len; | ||
330 | } | ||
331 | break; | ||
332 | |||
333 | default: | ||
334 | va_end (ap); | ||
335 | return -1; | ||
341 | } | 336 | } |
342 | 337 | ||
338 | ++fmt; | ||
339 | } | ||
340 | |||
343 | va_end (ap); | 341 | va_end (ap); |
344 | return 0; | 342 | return 0; |
345 | } | 343 | } |
diff --git a/src/plugins/old/pack.h b/src/plugins/old/pack.h index fe4e168..74bc172 100644 --- a/src/plugins/old/pack.h +++ b/src/plugins/old/pack.h | |||
@@ -45,18 +45,16 @@ MODIFICATIONS. | |||
45 | p - (unpack only) value is a pointer to a pointer. Generate the buffer | 45 | p - (unpack only) value is a pointer to a pointer. Generate the buffer |
46 | to hold the data. | 46 | to hold the data. |
47 | */ | 47 | */ |
48 | int | 48 | int |
49 | EXTRACTOR_common_cat_unpack(const void * buf, | 49 | EXTRACTOR_common_cat_unpack (const void *buf, |
50 | const char *fmt, | 50 | const char *fmt, |
51 | ...); | 51 | ...); |
52 | 52 | ||
53 | struct cat_bvec | 53 | struct cat_bvec |
54 | { | 54 | { |
55 | unsigned long len; | 55 | unsigned long len; |
56 | void * data; | 56 | void *data; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | 59 | ||
60 | #endif /* __CAT_PACK_H */ | 60 | #endif /* __CAT_PACK_H */ |
61 | |||
62 | |||
diff --git a/src/plugins/old/qt_extractor.c b/src/plugins/old/qt_extractor.c index f3420bb..2db3306 100644 --- a/src/plugins/old/qt_extractor.c +++ b/src/plugins/old/qt_extractor.c | |||
@@ -178,7 +178,7 @@ static const char *const genre_names[] = { | |||
178 | }; | 178 | }; |
179 | 179 | ||
180 | #define GENRE_NAME_COUNT \ | 180 | #define GENRE_NAME_COUNT \ |
181 | ((unsigned int)(sizeof genre_names / sizeof (const char *const))) | 181 | ((unsigned int) (sizeof genre_names / sizeof (const char *const))) |
182 | 182 | ||
183 | 183 | ||
184 | static const char *languages[] = { | 184 | static const char *languages[] = { |
@@ -299,7 +299,7 @@ typedef struct | |||
299 | const char *mime; | 299 | const char *mime; |
300 | } C2M; | 300 | } C2M; |
301 | 301 | ||
302 | /* see http://www.mp4ra.org/filetype.html | 302 | /* see http://www.mp4ra.org/filetype.html |
303 | * http://www.ftyps.com/ */ | 303 | * http://www.ftyps.com/ */ |
304 | static C2M ftMap[] = { | 304 | static C2M ftMap[] = { |
305 | {"qt ", "video/quicktime"}, | 305 | {"qt ", "video/quicktime"}, |
@@ -356,7 +356,7 @@ static CHE cHm[] = { | |||
356 | {"src", EXTRACTOR_METATYPE_CONTRIBUTOR_NAME}, | 356 | {"src", EXTRACTOR_METATYPE_CONTRIBUTOR_NAME}, |
357 | {"prf", EXTRACTOR_METATYPE_PERFORMER }, | 357 | {"prf", EXTRACTOR_METATYPE_PERFORMER }, |
358 | {"prd", EXTRACTOR_METATYPE_PRODUCER}, | 358 | {"prd", EXTRACTOR_METATYPE_PRODUCER}, |
359 | {"PRD", EXTRACTOR_METATYPE_PRODUCT_VERSION}, | 359 | {"PRD", EXTRACTOR_METATYPE_PRODUCT_VERSION}, |
360 | {"swr", EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE}, | 360 | {"swr", EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE}, |
361 | {"isr", EXTRACTOR_METATYPE_ISRC}, | 361 | {"isr", EXTRACTOR_METATYPE_ISRC}, |
362 | {"wrt", EXTRACTOR_METATYPE_WRITER}, | 362 | {"wrt", EXTRACTOR_METATYPE_WRITER}, |
@@ -396,7 +396,7 @@ static ITTagConversionEntry it_to_extr_table[] = { | |||
396 | {"keyw", EXTRACTOR_METATYPE_KEYWORDS}, | 396 | {"keyw", EXTRACTOR_METATYPE_KEYWORDS}, |
397 | {"desc", EXTRACTOR_METATYPE_DESCRIPTION}, | 397 | {"desc", EXTRACTOR_METATYPE_DESCRIPTION}, |
398 | {"tvnn", EXTRACTOR_METATYPE_NETWORK_NAME}, | 398 | {"tvnn", EXTRACTOR_METATYPE_NETWORK_NAME}, |
399 | {"tvsh", EXTRACTOR_METATYPE_SHOW_NAME}, | 399 | {"tvsh", EXTRACTOR_METATYPE_SHOW_NAME}, |
400 | {"tven", EXTRACTOR_METATYPE_NETWORK_NAME}, | 400 | {"tven", EXTRACTOR_METATYPE_NETWORK_NAME}, |
401 | {NULL, EXTRACTOR_METATYPE_RESERVED} | 401 | {NULL, EXTRACTOR_METATYPE_RESERVED} |
402 | }; | 402 | }; |
@@ -441,25 +441,26 @@ checkAtomValid (const char *buffer, size_t size, size_t pos) | |||
441 | return 0; | 441 | return 0; |
442 | atom = (const Atom *) &buffer[pos]; | 442 | atom = (const Atom *) &buffer[pos]; |
443 | if (ntohl (atom->size) == 1) | 443 | if (ntohl (atom->size) == 1) |
444 | { | 444 | { |
445 | if ((pos + sizeof (LongAtom) > size) || (pos + sizeof (LongAtom) < pos)) | 445 | if ((pos + sizeof (LongAtom) > size) || (pos + sizeof (LongAtom) < pos)) |
446 | return 0; | 446 | return 0; |
447 | latom = (const LongAtom *) &buffer[pos]; | 447 | latom = (const LongAtom *) &buffer[pos]; |
448 | atomSize = ntohll (latom->size); | 448 | atomSize = ntohll (latom->size); |
449 | if ((atomSize < sizeof (LongAtom)) || | 449 | if ((atomSize < sizeof (LongAtom)) || |
450 | (atomSize + pos > size) || (atomSize + pos < atomSize)) | 450 | (atomSize + pos > size) || (atomSize + pos < atomSize)) |
451 | return 0; | 451 | return 0; |
452 | } | 452 | } |
453 | else | 453 | else |
454 | { | 454 | { |
455 | atomSize = ntohl (atom->size); | 455 | atomSize = ntohl (atom->size); |
456 | if ((atomSize < sizeof (Atom)) || | 456 | if ((atomSize < sizeof (Atom)) || |
457 | (atomSize + pos > size) || (atomSize + pos < atomSize)) | 457 | (atomSize + pos > size) || (atomSize + pos < atomSize)) |
458 | return 0; | 458 | return 0; |
459 | } | 459 | } |
460 | return 1; | 460 | return 1; |
461 | } | 461 | } |
462 | 462 | ||
463 | |||
463 | /** | 464 | /** |
464 | * Assumes that checkAtomValid has already been called. | 465 | * Assumes that checkAtomValid has already been called. |
465 | */ | 466 | */ |
@@ -470,13 +471,14 @@ getAtomSize (const char *buf) | |||
470 | const LongAtom *latom; | 471 | const LongAtom *latom; |
471 | atom = (const Atom *) buf; | 472 | atom = (const Atom *) buf; |
472 | if (ntohl (atom->size) == 1) | 473 | if (ntohl (atom->size) == 1) |
473 | { | 474 | { |
474 | latom = (const LongAtom *) buf; | 475 | latom = (const LongAtom *) buf; |
475 | return ntohll (latom->size); | 476 | return ntohll (latom->size); |
476 | } | 477 | } |
477 | return ntohl (atom->size); | 478 | return ntohl (atom->size); |
478 | } | 479 | } |
479 | 480 | ||
481 | |||
480 | /** | 482 | /** |
481 | * Assumes that checkAtomValid has already been called. | 483 | * Assumes that checkAtomValid has already been called. |
482 | */ | 484 | */ |
@@ -491,6 +493,7 @@ getAtomHeaderSize (const char *buf) | |||
491 | return sizeof (Atom); | 493 | return sizeof (Atom); |
492 | } | 494 | } |
493 | 495 | ||
496 | |||
494 | struct ExtractContext | 497 | struct ExtractContext |
495 | { | 498 | { |
496 | EXTRACTOR_MetaDataProcessor proc; | 499 | EXTRACTOR_MetaDataProcessor proc; |
@@ -500,22 +503,21 @@ struct ExtractContext | |||
500 | 503 | ||
501 | static void | 504 | static void |
502 | addKeyword (enum EXTRACTOR_MetaType type, | 505 | addKeyword (enum EXTRACTOR_MetaType type, |
503 | const char *str, | 506 | const char *str, |
504 | struct ExtractContext *ec) | 507 | struct ExtractContext *ec) |
505 | { | 508 | { |
506 | if (ec->ret != 0) | 509 | if (ec->ret != 0) |
507 | return; | 510 | return; |
508 | ec->ret = ec->proc (ec->proc_cls, | 511 | ec->ret = ec->proc (ec->proc_cls, |
509 | "qt", | 512 | "qt", |
510 | type, | 513 | type, |
511 | EXTRACTOR_METAFORMAT_UTF8, | 514 | EXTRACTOR_METAFORMAT_UTF8, |
512 | "text/plain", | 515 | "text/plain", |
513 | str, | 516 | str, |
514 | strlen(str)+1); | 517 | strlen (str) + 1); |
515 | } | 518 | } |
516 | 519 | ||
517 | 520 | ||
518 | |||
519 | /** | 521 | /** |
520 | * Assumes that checkAtomValid has already been called. | 522 | * Assumes that checkAtomValid has already been called. |
521 | */ | 523 | */ |
@@ -538,8 +540,8 @@ typedef struct | |||
538 | static int handleAtom (HandlerEntry *handlers, | 540 | static int handleAtom (HandlerEntry *handlers, |
539 | const char *input, | 541 | const char *input, |
540 | size_t size, | 542 | size_t size, |
541 | size_t pos, | 543 | size_t pos, |
542 | struct ExtractContext *ec); | 544 | struct ExtractContext *ec); |
543 | 545 | ||
544 | static HandlerEntry all_handlers[]; | 546 | static HandlerEntry all_handlers[]; |
545 | static HandlerEntry ilst_handlers[]; | 547 | static HandlerEntry ilst_handlers[]; |
@@ -550,7 +552,7 @@ static HandlerEntry ilst_handlers[]; | |||
550 | */ | 552 | */ |
551 | static int | 553 | static int |
552 | processAtoms (HandlerEntry *handlers, const char *input, | 554 | processAtoms (HandlerEntry *handlers, const char *input, |
553 | size_t size, struct ExtractContext *ec) | 555 | size_t size, struct ExtractContext *ec) |
554 | { | 556 | { |
555 | size_t pos; | 557 | size_t pos; |
556 | 558 | ||
@@ -558,14 +560,15 @@ processAtoms (HandlerEntry *handlers, const char *input, | |||
558 | return 1; | 560 | return 1; |
559 | pos = 0; | 561 | pos = 0; |
560 | while (pos < size - sizeof (Atom)) | 562 | while (pos < size - sizeof (Atom)) |
561 | { | 563 | { |
562 | if (0 == handleAtom (handlers, input, size, pos, ec)) | 564 | if (0 == handleAtom (handlers, input, size, pos, ec)) |
563 | return 0; | 565 | return 0; |
564 | pos += getAtomSize (&input[pos]); | 566 | pos += getAtomSize (&input[pos]); |
565 | } | 567 | } |
566 | return 1; | 568 | return 1; |
567 | } | 569 | } |
568 | 570 | ||
571 | |||
569 | /** | 572 | /** |
570 | * Process all atoms. | 573 | * Process all atoms. |
571 | * @return 0 on error, 1 for success, -1 for unknown atom type | 574 | * @return 0 on error, 1 for success, -1 for unknown atom type |
@@ -574,9 +577,10 @@ static int | |||
574 | processAllAtoms (const char *input, | 577 | processAllAtoms (const char *input, |
575 | size_t size, struct ExtractContext *ec) | 578 | size_t size, struct ExtractContext *ec) |
576 | { | 579 | { |
577 | return processAtoms(all_handlers, input, size, ec); | 580 | return processAtoms (all_handlers, input, size, ec); |
578 | } | 581 | } |
579 | 582 | ||
583 | |||
580 | /** | 584 | /** |
581 | * Handle the moov atom. | 585 | * Handle the moov atom. |
582 | * @return 0 on error, 1 for success, -1 for unknown atom type | 586 | * @return 0 on error, 1 for success, -1 for unknown atom type |
@@ -590,6 +594,7 @@ moovHandler (const char *input, | |||
590 | getAtomSize (&input[pos]) - hdr, ec); | 594 | getAtomSize (&input[pos]) - hdr, ec); |
591 | } | 595 | } |
592 | 596 | ||
597 | |||
593 | /* see http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap1/chapter_2_section_5.html */ | 598 | /* see http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap1/chapter_2_section_5.html */ |
594 | typedef struct | 599 | typedef struct |
595 | { | 600 | { |
@@ -609,7 +614,8 @@ ftypHandler (const char *input, | |||
609 | const FileType *ft; | 614 | const FileType *ft; |
610 | int i; | 615 | int i; |
611 | 616 | ||
612 | if (getAtomSize (&input[pos]) < sizeof (FileType)) { | 617 | if (getAtomSize (&input[pos]) < sizeof (FileType)) |
618 | { | ||
613 | return 0; | 619 | return 0; |
614 | } | 620 | } |
615 | ft = (const FileType *) &input[pos]; | 621 | ft = (const FileType *) &input[pos]; |
@@ -622,6 +628,7 @@ ftypHandler (const char *input, | |||
622 | return 1; | 628 | return 1; |
623 | } | 629 | } |
624 | 630 | ||
631 | |||
625 | typedef struct | 632 | typedef struct |
626 | { | 633 | { |
627 | Atom hdr; | 634 | Atom hdr; |
@@ -662,13 +669,14 @@ mvhdHandler (const char *input, | |||
662 | return 0; | 669 | return 0; |
663 | m = (const MovieHeaderAtom *) &input[pos]; | 670 | m = (const MovieHeaderAtom *) &input[pos]; |
664 | snprintf (duration, | 671 | snprintf (duration, |
665 | sizeof(duration), | 672 | sizeof(duration), |
666 | "%us", | 673 | "%us", |
667 | ntohl (m->duration) / ntohl (m->timeScale)); | 674 | ntohl (m->duration) / ntohl (m->timeScale)); |
668 | addKeyword (EXTRACTOR_METATYPE_DURATION, duration, ec); | 675 | addKeyword (EXTRACTOR_METATYPE_DURATION, duration, ec); |
669 | return 1; | 676 | return 1; |
670 | } | 677 | } |
671 | 678 | ||
679 | |||
672 | typedef struct | 680 | typedef struct |
673 | { | 681 | { |
674 | Atom cmovAtom; | 682 | Atom cmovAtom; |
@@ -699,9 +707,9 @@ cmovHandler (const char *input, | |||
699 | (0 != memcmp (&c->cmvdAtom.type, "cmvd", 4)) || | 707 | (0 != memcmp (&c->cmvdAtom.type, "cmvd", 4)) || |
700 | (ntohl (c->cmvdAtom.size) != | 708 | (ntohl (c->cmvdAtom.size) != |
701 | getAtomSize (&input[pos]) - sizeof (Atom) * 2 - 4)) | 709 | getAtomSize (&input[pos]) - sizeof (Atom) * 2 - 4)) |
702 | { | 710 | { |
703 | return 0; /* dcom must be 12 bytes */ | 711 | return 0; /* dcom must be 12 bytes */ |
704 | } | 712 | } |
705 | s = ntohl (c->decompressedSize); | 713 | s = ntohl (c->decompressedSize); |
706 | if (s > 16 * 1024 * 1024) | 714 | if (s > 16 * 1024 * 1024) |
707 | return 1; /* ignore, too big! */ | 715 | return 1; /* ignore, too big! */ |
@@ -718,27 +726,28 @@ cmovHandler (const char *input, | |||
718 | z_state.opaque = (voidpf) 0; | 726 | z_state.opaque = (voidpf) 0; |
719 | z_ret_code = inflateInit (&z_state); | 727 | z_ret_code = inflateInit (&z_state); |
720 | if (Z_OK != z_ret_code) | 728 | if (Z_OK != z_ret_code) |
721 | { | 729 | { |
722 | free (buf); | 730 | free (buf); |
723 | return 0; /* crc error? */ | 731 | return 0; /* crc error? */ |
724 | } | 732 | } |
725 | z_ret_code = inflate (&z_state, Z_NO_FLUSH); | 733 | z_ret_code = inflate (&z_state, Z_NO_FLUSH); |
726 | if ((z_ret_code != Z_OK) && (z_ret_code != Z_STREAM_END)) | 734 | if ((z_ret_code != Z_OK) && (z_ret_code != Z_STREAM_END)) |
727 | { | 735 | { |
728 | free (buf); | 736 | free (buf); |
729 | return 0; /* decode error? */ | 737 | return 0; /* decode error? */ |
730 | } | 738 | } |
731 | z_ret_code = inflateEnd (&z_state); | 739 | z_ret_code = inflateEnd (&z_state); |
732 | if (Z_OK != z_ret_code) | 740 | if (Z_OK != z_ret_code) |
733 | { | 741 | { |
734 | free (buf); | 742 | free (buf); |
735 | return 0; /* decode error? */ | 743 | return 0; /* decode error? */ |
736 | } | 744 | } |
737 | ret = handleAtom (all_handlers, buf, s, 0, ec); | 745 | ret = handleAtom (all_handlers, buf, s, 0, ec); |
738 | free (buf); | 746 | free (buf); |
739 | return ret; | 747 | return ret; |
740 | } | 748 | } |
741 | 749 | ||
750 | |||
742 | typedef struct | 751 | typedef struct |
743 | { | 752 | { |
744 | short integer; | 753 | short integer; |
@@ -780,18 +789,19 @@ tkhdHandler (const char *input, | |||
780 | return 0; | 789 | return 0; |
781 | m = (const TrackAtom *) &input[pos]; | 790 | m = (const TrackAtom *) &input[pos]; |
782 | if (ntohs (m->track_width.integer) != 0) | 791 | if (ntohs (m->track_width.integer) != 0) |
783 | { | 792 | { |
784 | /* if actually a/the video track */ | 793 | /* if actually a/the video track */ |
785 | snprintf (dimensions, | 794 | snprintf (dimensions, |
786 | sizeof(dimensions), | 795 | sizeof(dimensions), |
787 | "%dx%d", | 796 | "%dx%d", |
788 | ntohs (m->track_width.integer), | 797 | ntohs (m->track_width.integer), |
789 | ntohs (m->track_height.integer)); | 798 | ntohs (m->track_height.integer)); |
790 | addKeyword (EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, dimensions, ec); | 799 | addKeyword (EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, dimensions, ec); |
791 | } | 800 | } |
792 | return 1; | 801 | return 1; |
793 | } | 802 | } |
794 | 803 | ||
804 | |||
795 | static int | 805 | static int |
796 | trakHandler (const char *input, | 806 | trakHandler (const char *input, |
797 | size_t size, size_t pos, struct ExtractContext *ec) | 807 | size_t size, size_t pos, struct ExtractContext *ec) |
@@ -801,6 +811,7 @@ trakHandler (const char *input, | |||
801 | getAtomSize (&input[pos]) - hdr, ec); | 811 | getAtomSize (&input[pos]) - hdr, ec); |
802 | } | 812 | } |
803 | 813 | ||
814 | |||
804 | static int | 815 | static int |
805 | metaHandler (const char *input, | 816 | metaHandler (const char *input, |
806 | size_t size, size_t pos, struct ExtractContext *ec) | 817 | size_t size, size_t pos, struct ExtractContext *ec) |
@@ -812,6 +823,7 @@ metaHandler (const char *input, | |||
812 | getAtomSize (&input[pos]) - hdr - 4, ec); | 823 | getAtomSize (&input[pos]) - hdr - 4, ec); |
813 | } | 824 | } |
814 | 825 | ||
826 | |||
815 | typedef struct | 827 | typedef struct |
816 | { | 828 | { |
817 | Atom header; | 829 | Atom header; |
@@ -873,13 +885,14 @@ c_Handler (const char *input, | |||
873 | int i; | 885 | int i; |
874 | 886 | ||
875 | i = 0; | 887 | i = 0; |
876 | while ((cHm[i].pfx != NULL) && (0 != memcmp (&input[pos+5], cHm[i].pfx, 3))) | 888 | while ((cHm[i].pfx != NULL) && (0 != memcmp (&input[pos + 5], cHm[i].pfx, 3))) |
877 | i++; | 889 | i++; |
878 | if (cHm[i].pfx != NULL) | 890 | if (cHm[i].pfx != NULL) |
879 | return processTextTag (input, size, pos, cHm[i].type, ec); | 891 | return processTextTag (input, size, pos, cHm[i].type, ec); |
880 | return -1; /* not found */ | 892 | return -1; /* not found */ |
881 | } | 893 | } |
882 | 894 | ||
895 | |||
883 | static int | 896 | static int |
884 | udtaHandler (const char *input, | 897 | udtaHandler (const char *input, |
885 | size_t size, size_t pos, struct ExtractContext *ec) | 898 | size_t size, size_t pos, struct ExtractContext *ec) |
@@ -889,13 +902,14 @@ udtaHandler (const char *input, | |||
889 | getAtomSize (&input[pos]) - hdr, ec); | 902 | getAtomSize (&input[pos]) - hdr, ec); |
890 | } | 903 | } |
891 | 904 | ||
905 | |||
892 | static int | 906 | static int |
893 | processDataAtom (const char *input, | 907 | processDataAtom (const char *input, |
894 | size_t size, /* parent atom size */ | 908 | size_t size, /* parent atom size */ |
895 | size_t pos, | 909 | size_t pos, |
896 | const char *patom, | 910 | const char *patom, |
897 | enum EXTRACTOR_MetaType type, | 911 | enum EXTRACTOR_MetaType type, |
898 | struct ExtractContext *ec) | 912 | struct ExtractContext *ec) |
899 | { | 913 | { |
900 | char *meta; | 914 | char *meta; |
901 | unsigned char version; | 915 | unsigned char version; |
@@ -907,55 +921,62 @@ processDataAtom (const char *input, | |||
907 | 921 | ||
908 | hdr = getAtomHeaderSize (&input[pos]); | 922 | hdr = getAtomHeaderSize (&input[pos]); |
909 | asize = getAtomSize (&input[pos]); | 923 | asize = getAtomSize (&input[pos]); |
910 | if (memcmp(&input[pos+4], "data", 4) != 0) | 924 | if (memcmp (&input[pos + 4], "data", 4) != 0) |
911 | return -1; | 925 | return -1; |
912 | 926 | ||
913 | if (asize < hdr + 8 || /* header + u32 flags + u32 reserved */ | 927 | if ((asize < hdr + 8) || /* header + u32 flags + u32 reserved */ |
914 | asize > (getAtomSize(&patom[0]) - 8)) | 928 | (asize > (getAtomSize (&patom[0]) - 8)) ) |
915 | return 0; | 929 | return 0; |
916 | 930 | ||
917 | len = (unsigned int)(asize - (hdr + 8)); | 931 | len = (unsigned int) (asize - (hdr + 8)); |
918 | 932 | ||
919 | version = input[pos+8]; | 933 | version = input[pos + 8]; |
920 | flags = ((unsigned char)input[pos+9]<<16) | | 934 | flags = ((unsigned char) input[pos + 9] << 16) |
921 | ((unsigned char)input[pos+10]<<8) | | 935 | | ((unsigned char) input[pos + 10] << 8) |
922 | (unsigned char)input[pos+11]; | 936 | | (unsigned char) input[pos + 11]; |
923 | #if DEBUG | 937 | #if DEBUG |
924 | printf("[data] version:%02x flags:%08x txtlen:%d\n", version, flags, len); | 938 | printf ("[data] version:%02x flags:%08x txtlen:%d\n", version, flags, len); |
925 | #endif | 939 | #endif |
926 | 940 | ||
927 | if (version != 0) | 941 | if (version != 0) |
928 | return -1; | 942 | return -1; |
929 | 943 | ||
930 | if (flags == 0x0) { /* binary data */ | 944 | if (flags == 0x0) /* binary data */ |
931 | if (memcmp(&patom[4], "gnre", 4) == 0) { | 945 | { |
932 | if (len >= 2) { | 946 | if (memcmp (&patom[4], "gnre", 4) == 0) |
933 | unsigned short genre = ((unsigned char)input[pos+16] << 8) | | 947 | { |
934 | (unsigned char)input[pos+17]; | 948 | if (len >= 2) |
935 | if (genre > 0 && genre < GENRE_NAME_COUNT) | 949 | { |
936 | addKeyword(type, genre_names[genre-1], ec); | 950 | unsigned short genre = ((unsigned char) input[pos + 16] << 8) |
951 | | (unsigned char) input[pos + 17]; | ||
952 | if ((genre > 0) && (genre < GENRE_NAME_COUNT)) | ||
953 | addKeyword (type, genre_names[genre - 1], ec); | ||
937 | } | 954 | } |
938 | return 1; | 955 | return 1; |
939 | } | 956 | } |
940 | else if ((memcmp(&patom[4], "trkn", 4) == 0) || | 957 | else if ((memcmp (&patom[4], "trkn", 4) == 0) || |
941 | (memcmp(&patom[4], "disk", 4) == 0)) { | 958 | (memcmp (&patom[4], "disk", 4) == 0)) |
942 | if (len >= 4) { | 959 | { |
943 | unsigned short n = ((unsigned char)input[pos+18] << 8) | | 960 | if (len >= 4) |
944 | (unsigned char)input[pos+19]; | 961 | { |
962 | unsigned short n = ((unsigned char) input[pos + 18] << 8) | ||
963 | | (unsigned char) input[pos + 19]; | ||
945 | char s[8]; | 964 | char s[8]; |
946 | snprintf(s, 8, "%d", n); | 965 | snprintf (s, 8, "%d", n); |
947 | addKeyword(type, s, ec); | 966 | addKeyword (type, s, ec); |
948 | } | 967 | } |
949 | } | 968 | } |
950 | else { | 969 | else |
970 | { | ||
951 | return -1; | 971 | return -1; |
952 | } | 972 | } |
953 | } | 973 | } |
954 | else if (flags == 0x1) { /* text data */ | 974 | else if (flags == 0x1) /* text data */ |
975 | { | ||
955 | meta = malloc (len + 1); | 976 | meta = malloc (len + 1); |
956 | if (meta == NULL) | 977 | if (meta == NULL) |
957 | return 0; | 978 | return 0; |
958 | memcpy (meta, &input[pos+16], len); | 979 | memcpy (meta, &input[pos + 16], len); |
959 | meta[len] = '\0'; | 980 | meta[len] = '\0'; |
960 | for (i = 0; i < len; i++) | 981 | for (i = 0; i < len; i++) |
961 | if (meta[i] == '\r') | 982 | if (meta[i] == '\r') |
@@ -968,12 +989,13 @@ processDataAtom (const char *input, | |||
968 | return -1; | 989 | return -1; |
969 | } | 990 | } |
970 | 991 | ||
992 | |||
971 | /* NOTE: iTunes tag processing should, in theory, be limited to iTunes | 993 | /* NOTE: iTunes tag processing should, in theory, be limited to iTunes |
972 | * file types (from ftyp), but, in reality, it seems that there are other | 994 | * file types (from ftyp), but, in reality, it seems that there are other |
973 | * files, like 3gpp, out in the wild with iTunes tags. */ | 995 | * files, like 3gpp, out in the wild with iTunes tags. */ |
974 | static int | 996 | static int |
975 | iTunesTagHandler (const char *input, | 997 | iTunesTagHandler (const char *input, |
976 | size_t size, size_t pos, struct ExtractContext *ec) | 998 | size_t size, size_t pos, struct ExtractContext *ec) |
977 | { | 999 | { |
978 | unsigned long long asize; | 1000 | unsigned long long asize; |
979 | unsigned int hdr; | 1001 | unsigned int hdr; |
@@ -986,24 +1008,24 @@ iTunesTagHandler (const char *input, | |||
986 | return 0; | 1008 | return 0; |
987 | 1009 | ||
988 | i = 0; | 1010 | i = 0; |
989 | while ((it_to_extr_table[i].atom_type != NULL) && | 1011 | while ((it_to_extr_table[i].atom_type != NULL) && |
990 | (0 != memcmp (&input[pos+4], it_to_extr_table[i].atom_type, 4))) | 1012 | (0 != memcmp (&input[pos + 4], it_to_extr_table[i].atom_type, 4))) |
991 | i++; | 1013 | i++; |
992 | if (it_to_extr_table[i].atom_type != NULL) | 1014 | if (it_to_extr_table[i].atom_type != NULL) |
993 | return processDataAtom(input, asize, pos+hdr, &input[pos], | 1015 | return processDataAtom (input, asize, pos + hdr, &input[pos], |
994 | it_to_extr_table[i].type, ec); | 1016 | it_to_extr_table[i].type, ec); |
995 | 1017 | ||
996 | return -1; | 1018 | return -1; |
997 | } | 1019 | } |
998 | 1020 | ||
999 | 1021 | ||
1000 | static int | 1022 | static int |
1001 | ilstHandler (const char *input, | 1023 | ilstHandler (const char *input, |
1002 | size_t size, size_t pos, struct ExtractContext *ec) | 1024 | size_t size, size_t pos, struct ExtractContext *ec) |
1003 | { | 1025 | { |
1004 | unsigned int hdr = getAtomHeaderSize (&input[pos]); | 1026 | unsigned int hdr = getAtomHeaderSize (&input[pos]); |
1005 | return processAtoms(ilst_handlers, &input[pos + hdr], | 1027 | return processAtoms (ilst_handlers, &input[pos + hdr], |
1006 | getAtomSize(&input[pos]) - hdr, ec); | 1028 | getAtomSize (&input[pos]) - hdr, ec); |
1007 | } | 1029 | } |
1008 | 1030 | ||
1009 | 1031 | ||
@@ -1099,23 +1121,23 @@ handleAtom (HandlerEntry *handlers, const char *input, | |||
1099 | { | 1121 | { |
1100 | int i; | 1122 | int i; |
1101 | if (0 == checkAtomValid (input, size, pos)) | 1123 | if (0 == checkAtomValid (input, size, pos)) |
1102 | { | 1124 | { |
1103 | return 0; | 1125 | return 0; |
1104 | } | 1126 | } |
1105 | i = 0; | 1127 | i = 0; |
1106 | while ((handlers[i].name != NULL) && | 1128 | while ((handlers[i].name != NULL) && |
1107 | (0 != memcmp (&input[pos + 4], handlers[i].name, 4))) | 1129 | (0 != memcmp (&input[pos + 4], handlers[i].name, 4))) |
1108 | i++; | 1130 | i++; |
1109 | if (handlers[i].name == NULL) | 1131 | if (handlers[i].name == NULL) |
1110 | { | 1132 | { |
1111 | #if DEBUG | 1133 | #if DEBUG |
1112 | char b[5]; | 1134 | char b[5]; |
1113 | memcpy (b, &input[pos + 4], 4); | 1135 | memcpy (b, &input[pos + 4], 4); |
1114 | b[4] = '\0'; | 1136 | b[4] = '\0'; |
1115 | printf ("No handler for `%s'\n", b); | 1137 | printf ("No handler for `%s'\n", b); |
1116 | #endif | 1138 | #endif |
1117 | return -1; | 1139 | return -1; |
1118 | } | 1140 | } |
1119 | i = handlers[i].handler (input, size, pos, ec); | 1141 | i = handlers[i].handler (input, size, pos, ec); |
1120 | #if DEBUG | 1142 | #if DEBUG |
1121 | printf ("Running handler for `%4s' at %u completed with result %d\n", | 1143 | printf ("Running handler for `%4s' at %u completed with result %d\n", |
@@ -1124,18 +1146,19 @@ handleAtom (HandlerEntry *handlers, const char *input, | |||
1124 | return i; | 1146 | return i; |
1125 | } | 1147 | } |
1126 | 1148 | ||
1149 | |||
1127 | /* mimetypes: | 1150 | /* mimetypes: |
1128 | video/quicktime: mov,qt: Quicktime animation; | 1151 | video/quicktime: mov,qt: Quicktime animation; |
1129 | video/x-quicktime: mov,qt: Quicktime animation; | 1152 | video/x-quicktime: mov,qt: Quicktime animation; |
1130 | application/x-quicktimeplayer: qtl: Quicktime list; | 1153 | application/x-quicktimeplayer: qtl: Quicktime list; |
1131 | */ | 1154 | */ |
1132 | 1155 | ||
1133 | int | 1156 | int |
1134 | EXTRACTOR_qt_extract (const char *data, | 1157 | EXTRACTOR_qt_extract (const char *data, |
1135 | size_t size, | 1158 | size_t size, |
1136 | EXTRACTOR_MetaDataProcessor proc, | 1159 | EXTRACTOR_MetaDataProcessor proc, |
1137 | void *proc_cls, | 1160 | void *proc_cls, |
1138 | const char *options) | 1161 | const char *options) |
1139 | { | 1162 | { |
1140 | struct ExtractContext ec; | 1163 | struct ExtractContext ec; |
1141 | ec.proc = proc; | 1164 | ec.proc = proc; |
@@ -1145,4 +1168,5 @@ EXTRACTOR_qt_extract (const char *data, | |||
1145 | return ec.ret; | 1168 | return ec.ret; |
1146 | } | 1169 | } |
1147 | 1170 | ||
1171 | |||
1148 | /* end of qt_extractor.c */ | 1172 | /* end of qt_extractor.c */ |
diff --git a/src/plugins/old/real_extractor.c b/src/plugins/old/real_extractor.c index 0ca343c..cfac031 100644 --- a/src/plugins/old/real_extractor.c +++ b/src/plugins/old/real_extractor.c | |||
@@ -77,9 +77,9 @@ typedef struct | |||
77 | 77 | ||
78 | 78 | ||
79 | static int | 79 | static int |
80 | processMediaProperties (const Media_Properties * prop, | 80 | processMediaProperties (const Media_Properties *prop, |
81 | EXTRACTOR_MetaDataProcessor proc, | 81 | EXTRACTOR_MetaDataProcessor proc, |
82 | void *proc_cls) | 82 | void *proc_cls) |
83 | { | 83 | { |
84 | 84 | ||
85 | UINT8 mime_type_size; | 85 | UINT8 mime_type_size; |
@@ -95,28 +95,29 @@ processMediaProperties (const Media_Properties * prop, | |||
95 | return 0; | 95 | return 0; |
96 | 96 | ||
97 | mime_type_size = prop->data[prop->stream_name_size]; | 97 | mime_type_size = prop->data[prop->stream_name_size]; |
98 | if (prop_size > prop->stream_name_size + sizeof (UINT8) + | 98 | if (prop_size > prop->stream_name_size + sizeof (UINT8) |
99 | +mime_type_size + sizeof (Media_Properties)) | 99 | + +mime_type_size + sizeof (Media_Properties)) |
100 | { | 100 | { |
101 | char data[mime_type_size + 1]; | 101 | char data[mime_type_size + 1]; |
102 | memcpy (data, &prop->data[prop->stream_name_size + 1], mime_type_size); | 102 | memcpy (data, &prop->data[prop->stream_name_size + 1], mime_type_size); |
103 | data[mime_type_size] = '\0'; | 103 | data[mime_type_size] = '\0'; |
104 | 104 | ||
105 | return proc (proc_cls, | 105 | return proc (proc_cls, |
106 | "real", | 106 | "real", |
107 | EXTRACTOR_METATYPE_MIMETYPE, | 107 | EXTRACTOR_METATYPE_MIMETYPE, |
108 | EXTRACTOR_METAFORMAT_UTF8, | 108 | EXTRACTOR_METAFORMAT_UTF8, |
109 | "text/plain", | 109 | "text/plain", |
110 | data, | 110 | data, |
111 | strlen (data)); | 111 | strlen (data)); |
112 | } | 112 | } |
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
115 | 115 | ||
116 | |||
116 | static int | 117 | static int |
117 | processContentDescription (const Content_Description * prop, | 118 | processContentDescription (const Content_Description *prop, |
118 | EXTRACTOR_MetaDataProcessor proc, | 119 | EXTRACTOR_MetaDataProcessor proc, |
119 | void *proc_cls) | 120 | void *proc_cls) |
120 | { | 121 | { |
121 | UINT16 author_len; | 122 | UINT16 author_len; |
122 | UINT16 copyright_len; | 123 | UINT16 copyright_len; |
@@ -137,23 +138,23 @@ processContentDescription (const Content_Description * prop, | |||
137 | title_len = ntohs (prop->title_len); | 138 | title_len = ntohs (prop->title_len); |
138 | if (prop_size <= title_len + sizeof (UINT16) + sizeof (Content_Description)) | 139 | if (prop_size <= title_len + sizeof (UINT16) + sizeof (Content_Description)) |
139 | return 0; | 140 | return 0; |
140 | author_len = ntohs (*(UINT16 *) & prop->data[title_len]); | 141 | author_len = ntohs (*(UINT16 *) &prop->data[title_len]); |
141 | if (prop_size <= title_len + sizeof (UINT16) | 142 | if (prop_size <= title_len + sizeof (UINT16) |
142 | + author_len + sizeof (Content_Description)) | 143 | + author_len + sizeof (Content_Description)) |
143 | return 0; | 144 | return 0; |
144 | 145 | ||
145 | copyright_len = ntohs (*(UINT16 *) & prop->data[title_len + | 146 | copyright_len = ntohs (*(UINT16 *) &prop->data[title_len |
146 | author_len + | 147 | + author_len |
147 | sizeof (UINT16)]); | 148 | + sizeof (UINT16)]); |
148 | 149 | ||
149 | if (prop_size <= title_len + 2 * sizeof (UINT16) | 150 | if (prop_size <= title_len + 2 * sizeof (UINT16) |
150 | + author_len + copyright_len + sizeof (Content_Description)) | 151 | + author_len + copyright_len + sizeof (Content_Description)) |
151 | return 0; | 152 | return 0; |
152 | 153 | ||
153 | comment_len = ntohs (*(UINT16 *) & prop->data[title_len + | 154 | comment_len = ntohs (*(UINT16 *) &prop->data[title_len |
154 | author_len + | 155 | + author_len |
155 | copyright_len + | 156 | + copyright_len |
156 | 2 * sizeof (UINT16)]); | 157 | + 2 * sizeof (UINT16)]); |
157 | 158 | ||
158 | if (prop_size < title_len + 3 * sizeof (UINT16) | 159 | if (prop_size < title_len + 3 * sizeof (UINT16) |
159 | + author_len + copyright_len + comment_len | 160 | + author_len + copyright_len + comment_len |
@@ -163,78 +164,79 @@ processContentDescription (const Content_Description * prop, | |||
163 | ret = 0; | 164 | ret = 0; |
164 | title = malloc (title_len + 1); | 165 | title = malloc (title_len + 1); |
165 | if (title != NULL) | 166 | if (title != NULL) |
166 | { | 167 | { |
167 | memcpy (title, &prop->data[0], title_len); | 168 | memcpy (title, &prop->data[0], title_len); |
168 | title[title_len] = '\0'; | 169 | title[title_len] = '\0'; |
169 | ret = proc (proc_cls, | 170 | ret = proc (proc_cls, |
170 | "real", | 171 | "real", |
171 | EXTRACTOR_METATYPE_TITLE, | 172 | EXTRACTOR_METATYPE_TITLE, |
172 | EXTRACTOR_METAFORMAT_UTF8, | 173 | EXTRACTOR_METAFORMAT_UTF8, |
173 | "text/plain", | 174 | "text/plain", |
174 | title, | 175 | title, |
175 | strlen (title)+1); | 176 | strlen (title) + 1); |
176 | free (title); | 177 | free (title); |
177 | } | 178 | } |
178 | if (ret != 0) | 179 | if (ret != 0) |
179 | return ret; | 180 | return ret; |
180 | 181 | ||
181 | author = malloc (author_len + 1); | 182 | author = malloc (author_len + 1); |
182 | if (author != NULL) | 183 | if (author != NULL) |
183 | { | 184 | { |
184 | memcpy (author, &prop->data[title_len + sizeof (UINT16)], author_len); | 185 | memcpy (author, &prop->data[title_len + sizeof (UINT16)], author_len); |
185 | author[author_len] = '\0'; | 186 | author[author_len] = '\0'; |
186 | ret = proc (proc_cls, | 187 | ret = proc (proc_cls, |
187 | "real", | 188 | "real", |
188 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 189 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
189 | EXTRACTOR_METAFORMAT_UTF8, | 190 | EXTRACTOR_METAFORMAT_UTF8, |
190 | "text/plain", | 191 | "text/plain", |
191 | author, | 192 | author, |
192 | strlen (author)+1); | 193 | strlen (author) + 1); |
193 | free (author); | 194 | free (author); |
194 | } | 195 | } |
195 | if (ret != 0) | 196 | if (ret != 0) |
196 | return ret; | 197 | return ret; |
197 | 198 | ||
198 | copyright = malloc (copyright_len + 1); | 199 | copyright = malloc (copyright_len + 1); |
199 | if (copyright != NULL) | 200 | if (copyright != NULL) |
200 | { | 201 | { |
201 | memcpy (copyright, | 202 | memcpy (copyright, |
202 | &prop->data[title_len + sizeof (UINT16) * 2 + author_len], | 203 | &prop->data[title_len + sizeof (UINT16) * 2 + author_len], |
203 | copyright_len); | 204 | copyright_len); |
204 | copyright[copyright_len] = '\0'; | 205 | copyright[copyright_len] = '\0'; |
205 | ret = proc (proc_cls, | 206 | ret = proc (proc_cls, |
206 | "real", | 207 | "real", |
207 | EXTRACTOR_METATYPE_COPYRIGHT, | 208 | EXTRACTOR_METATYPE_COPYRIGHT, |
208 | EXTRACTOR_METAFORMAT_UTF8, | 209 | EXTRACTOR_METAFORMAT_UTF8, |
209 | "text/plain", | 210 | "text/plain", |
210 | copyright, | 211 | copyright, |
211 | strlen (copyright)+1); | 212 | strlen (copyright) + 1); |
212 | free (copyright); | 213 | free (copyright); |
213 | } | 214 | } |
214 | if (ret != 0) | 215 | if (ret != 0) |
215 | return ret; | 216 | return ret; |
216 | 217 | ||
217 | comment = malloc (comment_len + 1); | 218 | comment = malloc (comment_len + 1); |
218 | if (comment != NULL) | 219 | if (comment != NULL) |
219 | { | 220 | { |
220 | memcpy (comment, | 221 | memcpy (comment, |
221 | &prop->data[title_len + sizeof (UINT16) * 3 + author_len + | 222 | &prop->data[title_len + sizeof (UINT16) * 3 + author_len |
222 | copyright_len], comment_len); | 223 | + copyright_len], comment_len); |
223 | comment[comment_len] = '\0'; | 224 | comment[comment_len] = '\0'; |
224 | ret = proc (proc_cls, | 225 | ret = proc (proc_cls, |
225 | "real", | 226 | "real", |
226 | EXTRACTOR_METATYPE_COMMENT, | 227 | EXTRACTOR_METATYPE_COMMENT, |
227 | EXTRACTOR_METAFORMAT_UTF8, | 228 | EXTRACTOR_METAFORMAT_UTF8, |
228 | "text/plain", | 229 | "text/plain", |
229 | comment, | 230 | comment, |
230 | strlen (comment)+1); | 231 | strlen (comment) + 1); |
231 | free (comment); | 232 | free (comment); |
232 | } | 233 | } |
233 | if (ret != 0) | 234 | if (ret != 0) |
234 | return ret; | 235 | return ret; |
235 | return 0; | 236 | return 0; |
236 | } | 237 | } |
237 | 238 | ||
239 | |||
238 | typedef struct RAFF4_header | 240 | typedef struct RAFF4_header |
239 | { | 241 | { |
240 | unsigned short version; | 242 | unsigned short version; |
@@ -281,13 +283,14 @@ stndup (const char *str, size_t n) | |||
281 | return tmp; | 283 | return tmp; |
282 | } | 284 | } |
283 | 285 | ||
286 | |||
284 | /* audio/vnd.rn-realaudio */ | 287 | /* audio/vnd.rn-realaudio */ |
285 | int | 288 | int |
286 | EXTRACTOR_real_extract (const unsigned char *data, | 289 | EXTRACTOR_real_extract (const unsigned char *data, |
287 | size_t size, | 290 | size_t size, |
288 | EXTRACTOR_MetaDataProcessor proc, | 291 | EXTRACTOR_MetaDataProcessor proc, |
289 | void *proc_cls, | 292 | void *proc_cls, |
290 | const char *options) | 293 | const char *options) |
291 | { | 294 | { |
292 | const unsigned char *pos; | 295 | const unsigned char *pos; |
293 | const unsigned char *end; | 296 | const unsigned char *end; |
@@ -303,132 +306,134 @@ EXTRACTOR_real_extract (const unsigned char *data, | |||
303 | if (size <= 2 * sizeof (int)) | 306 | if (size <= 2 * sizeof (int)) |
304 | return 0; | 307 | return 0; |
305 | if (RAFF4_HEADER == ntohl (*(int *) data)) | 308 | if (RAFF4_HEADER == ntohl (*(int *) data)) |
309 | { | ||
310 | /* HELIX */ | ||
311 | if (size <= RAFF4_HDR_SIZE + 16 + 4) | ||
312 | return 0; | ||
313 | if (0 != proc (proc_cls, | ||
314 | "real", | ||
315 | EXTRACTOR_METATYPE_MIMETYPE, | ||
316 | EXTRACTOR_METAFORMAT_UTF8, | ||
317 | "text/plain", | ||
318 | "audio/vnd.rn-realaudio", | ||
319 | strlen ("audio/vnd.rn-realaudio") + 1)) | ||
320 | return 1; | ||
321 | hdr = (const RAFF4_header *) &data[16]; | ||
322 | if (ntohs (hdr->header_length) + 16 > size) | ||
323 | return 0; | ||
324 | tlen = data[16 + RAFF4_HDR_SIZE]; | ||
325 | if (tlen + RAFF4_HDR_SIZE + 20 > size) | ||
326 | return 0; | ||
327 | alen = data[17 + tlen + RAFF4_HDR_SIZE]; | ||
328 | if (tlen + alen + RAFF4_HDR_SIZE + 20 > size) | ||
329 | return 0; | ||
330 | clen = data[18 + tlen + alen + RAFF4_HDR_SIZE]; | ||
331 | if (tlen + alen + clen + RAFF4_HDR_SIZE + 20 > size) | ||
332 | return 0; | ||
333 | aplen = data[19 + tlen + clen + alen + RAFF4_HDR_SIZE]; | ||
334 | if (tlen + alen + clen + aplen + RAFF4_HDR_SIZE + 20 > size) | ||
335 | return 0; | ||
336 | ret = 0; | ||
337 | if ( (tlen > 0) && (ret == 0) ) | ||
306 | { | 338 | { |
307 | /* HELIX */ | 339 | x = stndup ((const char *) &data[17 + RAFF4_HDR_SIZE], tlen); |
308 | if (size <= RAFF4_HDR_SIZE + 16 + 4) | 340 | if (x != NULL) |
309 | return 0; | 341 | { |
310 | if (0 != proc (proc_cls, | 342 | ret = proc (proc_cls, |
311 | "real", | 343 | "real", |
312 | EXTRACTOR_METATYPE_MIMETYPE, | 344 | EXTRACTOR_METATYPE_MIMETYPE, |
313 | EXTRACTOR_METAFORMAT_UTF8, | 345 | EXTRACTOR_METAFORMAT_UTF8, |
314 | "text/plain", | 346 | "text/plain", |
315 | "audio/vnd.rn-realaudio", | 347 | x, |
316 | strlen ("audio/vnd.rn-realaudio")+1)) | 348 | strlen (x) + 1); |
317 | return 1; | 349 | free (x); |
318 | hdr = (const RAFF4_header *) &data[16]; | 350 | } |
319 | if (ntohs (hdr->header_length) + 16 > size) | ||
320 | return 0; | ||
321 | tlen = data[16 + RAFF4_HDR_SIZE]; | ||
322 | if (tlen + RAFF4_HDR_SIZE + 20 > size) | ||
323 | return 0; | ||
324 | alen = data[17 + tlen + RAFF4_HDR_SIZE]; | ||
325 | if (tlen + alen + RAFF4_HDR_SIZE + 20 > size) | ||
326 | return 0; | ||
327 | clen = data[18 + tlen + alen + RAFF4_HDR_SIZE]; | ||
328 | if (tlen + alen + clen + RAFF4_HDR_SIZE + 20 > size) | ||
329 | return 0; | ||
330 | aplen = data[19 + tlen + clen + alen + RAFF4_HDR_SIZE]; | ||
331 | if (tlen + alen + clen + aplen + RAFF4_HDR_SIZE + 20 > size) | ||
332 | return 0; | ||
333 | ret = 0; | ||
334 | if ( (tlen > 0) && (ret == 0) ) | ||
335 | { | ||
336 | x = stndup ((const char *) &data[17 + RAFF4_HDR_SIZE], tlen); | ||
337 | if (x != NULL) | ||
338 | { | ||
339 | ret = proc (proc_cls, | ||
340 | "real", | ||
341 | EXTRACTOR_METATYPE_MIMETYPE, | ||
342 | EXTRACTOR_METAFORMAT_UTF8, | ||
343 | "text/plain", | ||
344 | x, | ||
345 | strlen (x)+1); | ||
346 | free (x); | ||
347 | } | ||
348 | } | ||
349 | if ( (alen > 0) && (ret == 0) ) | ||
350 | { | ||
351 | x = stndup ((const char *) &data[18 + RAFF4_HDR_SIZE + tlen], alen); | ||
352 | if (x != NULL) | ||
353 | { | ||
354 | ret = proc (proc_cls, | ||
355 | "real", | ||
356 | EXTRACTOR_METATYPE_MIMETYPE, | ||
357 | EXTRACTOR_METAFORMAT_UTF8, | ||
358 | "text/plain", | ||
359 | x, | ||
360 | strlen (x)+1); | ||
361 | free (x); | ||
362 | } | ||
363 | } | ||
364 | if ( (clen > 0) && (ret == 0) ) | ||
365 | { | ||
366 | x = stndup ((const char *) &data[19 + RAFF4_HDR_SIZE + tlen + alen], clen); | ||
367 | if (x != NULL) | ||
368 | { | ||
369 | ret = proc (proc_cls, | ||
370 | "real", | ||
371 | EXTRACTOR_METATYPE_MIMETYPE, | ||
372 | EXTRACTOR_METAFORMAT_UTF8, | ||
373 | "text/plain", | ||
374 | x, | ||
375 | strlen (x)+1); | ||
376 | free (x); | ||
377 | } | ||
378 | } | ||
379 | if ( (aplen > 0) && (ret == 0) ) | ||
380 | { | ||
381 | x = stndup ((const char *) &data[20 + RAFF4_HDR_SIZE + tlen + alen + clen], aplen); | ||
382 | if (x != NULL) | ||
383 | { | ||
384 | ret = proc (proc_cls, | ||
385 | "real", | ||
386 | EXTRACTOR_METATYPE_MIMETYPE, | ||
387 | EXTRACTOR_METAFORMAT_UTF8, | ||
388 | "text/plain", | ||
389 | x, | ||
390 | strlen (x)+1); | ||
391 | free (x); | ||
392 | } | ||
393 | } | ||
394 | return ret; | ||
395 | } | 351 | } |
352 | if ( (alen > 0) && (ret == 0) ) | ||
353 | { | ||
354 | x = stndup ((const char *) &data[18 + RAFF4_HDR_SIZE + tlen], alen); | ||
355 | if (x != NULL) | ||
356 | { | ||
357 | ret = proc (proc_cls, | ||
358 | "real", | ||
359 | EXTRACTOR_METATYPE_MIMETYPE, | ||
360 | EXTRACTOR_METAFORMAT_UTF8, | ||
361 | "text/plain", | ||
362 | x, | ||
363 | strlen (x) + 1); | ||
364 | free (x); | ||
365 | } | ||
366 | } | ||
367 | if ( (clen > 0) && (ret == 0) ) | ||
368 | { | ||
369 | x = stndup ((const char *) &data[19 + RAFF4_HDR_SIZE + tlen + alen], | ||
370 | clen); | ||
371 | if (x != NULL) | ||
372 | { | ||
373 | ret = proc (proc_cls, | ||
374 | "real", | ||
375 | EXTRACTOR_METATYPE_MIMETYPE, | ||
376 | EXTRACTOR_METAFORMAT_UTF8, | ||
377 | "text/plain", | ||
378 | x, | ||
379 | strlen (x) + 1); | ||
380 | free (x); | ||
381 | } | ||
382 | } | ||
383 | if ( (aplen > 0) && (ret == 0) ) | ||
384 | { | ||
385 | x = stndup ((const char *) &data[20 + RAFF4_HDR_SIZE + tlen + alen | ||
386 | + clen], aplen); | ||
387 | if (x != NULL) | ||
388 | { | ||
389 | ret = proc (proc_cls, | ||
390 | "real", | ||
391 | EXTRACTOR_METATYPE_MIMETYPE, | ||
392 | EXTRACTOR_METAFORMAT_UTF8, | ||
393 | "text/plain", | ||
394 | x, | ||
395 | strlen (x) + 1); | ||
396 | free (x); | ||
397 | } | ||
398 | } | ||
399 | return ret; | ||
400 | } | ||
396 | if (REAL_HEADER == ntohl (*(int *) data)) | 401 | if (REAL_HEADER == ntohl (*(int *) data)) |
402 | { | ||
403 | /* old real */ | ||
404 | end = &data[size]; | ||
405 | pos = &data[0]; | ||
406 | ret = 0; | ||
407 | while (0 == ret) | ||
397 | { | 408 | { |
398 | /* old real */ | 409 | if ((pos + 8 >= end) || (pos + 8 < pos)) |
399 | end = &data[size]; | 410 | break; |
400 | pos = &data[0]; | 411 | length = ntohl (*(((unsigned int *) pos) + 1)); |
401 | ret = 0; | 412 | if (length <= 0) |
402 | while (0 == ret) | 413 | break; |
403 | { | 414 | if ((pos + length >= end) || (pos + length < pos)) |
404 | if ((pos + 8 >= end) || (pos + 8 < pos)) | 415 | break; |
405 | break; | 416 | switch (ntohl (*((unsigned int *) pos))) |
406 | length = ntohl (*(((unsigned int *) pos) + 1)); | 417 | { |
407 | if (length <= 0) | 418 | case MDPR_HEADER: |
408 | break; | 419 | ret = processMediaProperties ((Media_Properties *) pos, |
409 | if ((pos + length >= end) || (pos + length < pos)) | 420 | proc, |
410 | break; | 421 | proc_cls); |
411 | switch (ntohl (*((unsigned int *) pos))) | 422 | pos += length; |
412 | { | 423 | break; |
413 | case MDPR_HEADER: | 424 | case CONT_HEADER: |
414 | ret = processMediaProperties ((Media_Properties *) pos, | 425 | ret = processContentDescription ((Content_Description *) pos, |
415 | proc, | 426 | proc, |
416 | proc_cls); | 427 | proc_cls); |
417 | pos += length; | 428 | pos += length; |
418 | break; | 429 | break; |
419 | case CONT_HEADER: | 430 | case REAL_HEADER: /* treat like default */ |
420 | ret = processContentDescription ((Content_Description *) pos, | 431 | default: |
421 | proc, | 432 | pos += length; |
422 | proc_cls); | 433 | break; |
423 | pos += length; | 434 | } |
424 | break; | ||
425 | case REAL_HEADER: /* treat like default */ | ||
426 | default: | ||
427 | pos += length; | ||
428 | break; | ||
429 | } | ||
430 | } | ||
431 | return ret; | ||
432 | } | 435 | } |
436 | return ret; | ||
437 | } | ||
433 | return 0; | 438 | return 0; |
434 | } | 439 | } |