diff options
-rw-r--r-- | src/plugins/Makefile.am | 19 | ||||
-rw-r--r-- | src/plugins/wav_extractor.c (renamed from src/plugins/wavextractor.c) | 57 |
2 files changed, 39 insertions, 37 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 2898f97..3463654 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am | |||
@@ -88,7 +88,8 @@ plugin_LTLIBRARIES = \ | |||
88 | $(pdf) \ | 88 | $(pdf) \ |
89 | libextractor_real.la \ | 89 | libextractor_real.la \ |
90 | $(rpm) \ | 90 | $(rpm) \ |
91 | $(thumbgtk) | 91 | $(thumbgtk) \ |
92 | libextractor_wav.la | ||
92 | 93 | ||
93 | libextractor_applefile_la_SOURCES = \ | 94 | libextractor_applefile_la_SOURCES = \ |
94 | applefile_extractor.c | 95 | applefile_extractor.c |
@@ -244,6 +245,14 @@ libextractor_thumbnailgtk_la_LDFLAGS = \ | |||
244 | libextractor_thumbnailgtk_la_SOURCES = \ | 245 | libextractor_thumbnailgtk_la_SOURCES = \ |
245 | thumbnailgtk_extractor.c | 246 | thumbnailgtk_extractor.c |
246 | 247 | ||
248 | libextractor_wav_la_SOURCES = \ | ||
249 | wav_extractor.c | ||
250 | libextractor_wav_la_LDFLAGS = \ | ||
251 | $(PLUGINFLAGS) | ||
252 | libextractor_wav_la_LIBADD = \ | ||
253 | $(LE_LIBINTL) | ||
254 | |||
255 | |||
247 | 256 | ||
248 | 257 | ||
249 | 258 | ||
@@ -268,7 +277,6 @@ OLD_LIBS = \ | |||
268 | libextractor_tar.la \ | 277 | libextractor_tar.la \ |
269 | libextractor_tiff.la \ | 278 | libextractor_tiff.la \ |
270 | $(thumbqt) \ | 279 | $(thumbqt) \ |
271 | libextractor_wav.la \ | ||
272 | libextractor_xm.la \ | 280 | libextractor_xm.la \ |
273 | libextractor_zip.la | 281 | libextractor_zip.la |
274 | 282 | ||
@@ -288,13 +296,6 @@ libextractor_ps_la_LDFLAGS = \ | |||
288 | libextractor_ps_la_LIBADD = \ | 296 | libextractor_ps_la_LIBADD = \ |
289 | $(top_builddir)/src/main/libextractor.la | 297 | $(top_builddir)/src/main/libextractor.la |
290 | 298 | ||
291 | libextractor_wav_la_SOURCES = \ | ||
292 | wavextractor.c | ||
293 | libextractor_wav_la_LDFLAGS = \ | ||
294 | $(PLUGINFLAGS) | ||
295 | libextractor_wav_la_LIBADD = \ | ||
296 | $(LE_LIBINTL) | ||
297 | |||
298 | libextractor_id3v2_la_SOURCES = \ | 299 | libextractor_id3v2_la_SOURCES = \ |
299 | id3v2extractor.c | 300 | id3v2extractor.c |
300 | libextractor_id3v2_la_LDFLAGS = \ | 301 | libextractor_id3v2_la_LDFLAGS = \ |
diff --git a/src/plugins/wavextractor.c b/src/plugins/wav_extractor.c index d97a568..b50ebc2 100644 --- a/src/plugins/wavextractor.c +++ b/src/plugins/wav_extractor.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libextractor. | 2 | This file is part of libextractor. |
3 | (C) 2004 Vidyut Samanta and Christian Grothoff | 3 | (C) 2004, 2009 Vidyut Samanta and Christian Grothoff |
4 | 4 | ||
5 | libextractor is free software; you can redistribute it and/or modify | 5 | libextractor is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -28,19 +28,6 @@ | |||
28 | 28 | ||
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "extractor.h" | 30 | #include "extractor.h" |
31 | #include "pack.h" | ||
32 | |||
33 | static void | ||
34 | addKeyword (struct EXTRACTOR_Keywords **list, | ||
35 | char *keyword, EXTRACTOR_KeywordType type) | ||
36 | { | ||
37 | EXTRACTOR_KeywordList *next; | ||
38 | next = malloc (sizeof (EXTRACTOR_KeywordList)); | ||
39 | next->next = *list; | ||
40 | next->keyword = keyword; | ||
41 | next->keywordType = type; | ||
42 | *list = next; | ||
43 | } | ||
44 | 31 | ||
45 | #if BIG_ENDIAN_HOST | 32 | #if BIG_ENDIAN_HOST |
46 | static short | 33 | static short |
@@ -70,18 +57,19 @@ toLittleEndian32 (unsigned int in) | |||
70 | 22 2 bytes <channels> // Channels: 1 = mono, 2 = stereo | 57 | 22 2 bytes <channels> // Channels: 1 = mono, 2 = stereo |
71 | 24 4 bytes <sample rate> // Samples per second: e.g., 44100 | 58 | 24 4 bytes <sample rate> // Samples per second: e.g., 44100 |
72 | */ | 59 | */ |
73 | struct EXTRACTOR_Keywords * | 60 | int |
74 | libextractor_wav_extract (char *filename, | 61 | EXTRACTOR_wav_extract (const unsigned char *buf, |
75 | const unsigned char *buf, | 62 | size_t bufLen, |
76 | size_t bufLen, struct EXTRACTOR_Keywords *prev) | 63 | EXTRACTOR_MetaDataProcessor proc, |
64 | void *proc_cls, | ||
65 | const char *options) | ||
77 | { | 66 | { |
78 | unsigned short channels; | 67 | unsigned short channels; |
79 | unsigned short sampleSize; | 68 | unsigned short sampleSize; |
80 | unsigned int sampleRate; | 69 | unsigned int sampleRate; |
81 | unsigned int dataLen; | 70 | unsigned int dataLen; |
82 | unsigned int samples; | 71 | unsigned int samples; |
83 | char *scratch; | 72 | char scratch[256]; |
84 | |||
85 | 73 | ||
86 | if ((bufLen < 44) || | 74 | if ((bufLen < 44) || |
87 | (buf[0] != 'R' || buf[1] != 'I' || | 75 | (buf[0] != 'R' || buf[1] != 'I' || |
@@ -89,7 +77,7 @@ libextractor_wav_extract (char *filename, | |||
89 | buf[8] != 'W' || buf[9] != 'A' || | 77 | buf[8] != 'W' || buf[9] != 'A' || |
90 | buf[10] != 'V' || buf[11] != 'E' || | 78 | buf[10] != 'V' || buf[11] != 'E' || |
91 | buf[12] != 'f' || buf[13] != 'm' || buf[14] != 't' || buf[15] != ' ')) | 79 | buf[12] != 'f' || buf[13] != 'm' || buf[14] != 't' || buf[15] != ' ')) |
92 | return prev; /* not a WAV file */ | 80 | return 0; /* not a WAV file */ |
93 | 81 | ||
94 | channels = *((unsigned short *) &buf[22]); | 82 | channels = *((unsigned short *) &buf[22]); |
95 | sampleRate = *((unsigned int *) &buf[24]); | 83 | sampleRate = *((unsigned int *) &buf[24]); |
@@ -104,20 +92,33 @@ libextractor_wav_extract (char *filename, | |||
104 | #endif | 92 | #endif |
105 | 93 | ||
106 | if (sampleSize != 8 && sampleSize != 16) | 94 | if (sampleSize != 8 && sampleSize != 16) |
107 | return prev; /* invalid sample size found in wav file */ | 95 | return 0; /* invalid sample size found in wav file */ |
108 | if (channels == 0) | 96 | if (channels == 0) |
109 | return prev; /* invalid channels value -- avoid division by 0! */ | 97 | return 0; /* invalid channels value -- avoid division by 0! */ |
110 | samples = dataLen / (channels * (sampleSize >> 3)); | 98 | samples = dataLen / (channels * (sampleSize >> 3)); |
111 | 99 | ||
112 | scratch = malloc (256); | ||
113 | snprintf (scratch, | 100 | snprintf (scratch, |
114 | 256, | 101 | sizeof (scratch), |
115 | "%u ms, %d Hz, %s", | 102 | "%u ms, %d Hz, %s", |
116 | (samples < sampleRate) | 103 | (samples < sampleRate) |
117 | ? (samples * 1000 / sampleRate) | 104 | ? (samples * 1000 / sampleRate) |
118 | : (samples / sampleRate) * 1000, | 105 | : (samples / sampleRate) * 1000, |
119 | sampleRate, channels == 1 ? _("mono") : _("stereo")); | 106 | sampleRate, channels == 1 ? _("mono") : _("stereo")); |
120 | addKeyword (&prev, scratch, EXTRACTOR_FORMAT); | 107 | if (0 != proc (proc_cls, |
121 | addKeyword (&prev, strdup ("audio/x-wav"), EXTRACTOR_MIMETYPE); | 108 | "wav", |
122 | return prev; | 109 | EXTRACTOR_METATYPE_RESOURCE_TYPE, |
110 | EXTRACTOR_METAFORMAT_UTF8, | ||
111 | "text/plain", | ||
112 | scratch, | ||
113 | strlen (scratch) +1)) | ||
114 | return 1; | ||
115 | if (0 != proc (proc_cls, | ||
116 | "wav", | ||
117 | EXTRACTOR_METATYPE_MIMETYPE, | ||
118 | EXTRACTOR_METAFORMAT_UTF8, | ||
119 | "text/plain", | ||
120 | "audio/x-wav", | ||
121 | strlen ("audio/x-wav") +1)) | ||
122 | return 1; | ||
123 | return 0; | ||
123 | } | 124 | } |