diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Makefile.am | 10 | ||||
-rw-r--r-- | src/plugins/ogg_extractor.c | 84 |
2 files changed, 50 insertions, 44 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index bdf8e2b..f5e8556 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am | |||
@@ -16,6 +16,7 @@ plugin_LTLIBRARIES = \ | |||
16 | libextractor_id3v2.la \ | 16 | libextractor_id3v2.la \ |
17 | libextractor_ebml.la \ | 17 | libextractor_ebml.la \ |
18 | libextractor_s3m.la \ | 18 | libextractor_s3m.la \ |
19 | libextractor_ogg.la \ | ||
19 | libextractor_mp3.la | 20 | libextractor_mp3.la |
20 | 21 | ||
21 | libextractor_mp3_la_SOURCES = \ | 22 | libextractor_mp3_la_SOURCES = \ |
@@ -58,4 +59,13 @@ libextractor_s3m_la_LIBADD = \ | |||
58 | $(top_builddir)/src/main/libextractor.la \ | 59 | $(top_builddir)/src/main/libextractor.la \ |
59 | $(top_builddir)/src/common/libextractor_common.la | 60 | $(top_builddir)/src/common/libextractor_common.la |
60 | 61 | ||
62 | libextractor_ogg_la_SOURCES = \ | ||
63 | ogg_extractor.c | ||
64 | libextractor_ogg_la_LDFLAGS = \ | ||
65 | $(PLUGINFLAGS) | ||
66 | libextractor_ogg_la_LIBADD = \ | ||
67 | $(top_builddir)/src/main/libextractor.la \ | ||
68 | $(top_builddir)/src/common/libextractor_common.la \ | ||
69 | -lvorbisfile -lvorbis $(vorbisflag) -logg | ||
70 | |||
61 | EXTRA_DIST = template_extractor.c | 71 | EXTRA_DIST = template_extractor.c |
diff --git a/src/plugins/ogg_extractor.c b/src/plugins/ogg_extractor.c index eef6fa9..a9c4f05 100644 --- a/src/plugins/ogg_extractor.c +++ b/src/plugins/ogg_extractor.c | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include "platform.h" | 21 | #include "platform.h" |
22 | #include "extractor.h" | 22 | #include "extractor.h" |
23 | #include "extractor_plugins.h" | ||
23 | 24 | ||
24 | #define DEBUG_EXTRACT_OGG 0 | 25 | #define DEBUG_EXTRACT_OGG 0 |
25 | #define OGG_HEADER 0x4f676753 | 26 | #define OGG_HEADER 0x4f676753 |
@@ -40,27 +41,21 @@ get_comment (vorbis_comment * vc, char *label) | |||
40 | } | 41 | } |
41 | 42 | ||
42 | static size_t | 43 | static size_t |
43 | readError (void *ptr, size_t size, size_t nmemb, void *datasource) | 44 | readOgg (void *ptr, size_t size, size_t nmemb, void *datasource) |
44 | { | 45 | { |
45 | return -1; | 46 | struct EXTRACTOR_PluginList *plugin = datasource; |
46 | } | 47 | int64_t ret; |
47 | 48 | unsigned char *read_data; | |
48 | static int | ||
49 | seekError (void *datasource, int64_t offset, int whence) | ||
50 | { | ||
51 | return -1; | ||
52 | } | ||
53 | |||
54 | static int | ||
55 | closeOk (void *datasource) | ||
56 | { | ||
57 | return 0; | ||
58 | } | ||
59 | 49 | ||
60 | static long | 50 | ret = pl_read (plugin, &read_data, size*nmemb); |
61 | tellError (void *datasource) | 51 | if (ret <= 0) |
62 | { | 52 | { |
63 | return -1; | 53 | if (ret < 0) |
54 | errno = EIO; | ||
55 | return 0; | ||
56 | } | ||
57 | memcpy (ptr, read_data, ret); | ||
58 | return ret; | ||
64 | } | 59 | } |
65 | 60 | ||
66 | #define ADD(t,s) do { if (0 != (ret = proc (proc_cls, "ogg", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto FINISH; } while (0) | 61 | #define ADD(t,s) do { if (0 != (ret = proc (proc_cls, "ogg", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto FINISH; } while (0) |
@@ -68,38 +63,39 @@ tellError (void *datasource) | |||
68 | #define ADDG(t,d) do { m = get_comment (comments, d); if (m != NULL) ADD(t,m); } while (0) | 63 | #define ADDG(t,d) do { m = get_comment (comments, d); if (m != NULL) ADD(t,m); } while (0) |
69 | 64 | ||
70 | /* mimetype = application/ogg */ | 65 | /* mimetype = application/ogg */ |
71 | int | 66 | int |
72 | EXTRACTOR_ogg_extract (const char *data, | 67 | EXTRACTOR_ogg_extract_method (struct EXTRACTOR_PluginList *plugin, |
73 | size_t size, | 68 | EXTRACTOR_MetaDataProcessor proc, void *proc_cls) |
74 | EXTRACTOR_MetaDataProcessor proc, | ||
75 | void *proc_cls, | ||
76 | const char *options) | ||
77 | { | 69 | { |
78 | OggVorbis_File vf; | 70 | OggVorbis_File vf; |
79 | vorbis_comment *comments; | 71 | vorbis_comment *comments; |
80 | ov_callbacks callbacks; | 72 | ov_callbacks callbacks; |
81 | int ret; | 73 | int ret; |
74 | int64_t fsize; | ||
82 | const char *m; | 75 | const char *m; |
83 | 76 | ||
84 | if (size < 2 * sizeof (int)) | 77 | fsize = pl_get_fsize (plugin); |
85 | return 0; | 78 | if (fsize > 0 && fsize < 2 * sizeof (int)) |
86 | if (OGG_HEADER != ntohl (*(int *) data)) | 79 | return 1; |
87 | return 0; | 80 | if (fsize == 0) |
88 | callbacks.read_func = &readError; | 81 | return 1; |
89 | callbacks.seek_func = &seekError; | 82 | |
90 | callbacks.close_func = &closeOk; | 83 | /* TODO: rewrite pl_seek() to be STDIO-compatible (SEEK_END) and enable seeking. */ |
91 | callbacks.tell_func = &tellError; | 84 | callbacks.read_func = &readOgg; |
92 | if (0 != ov_open_callbacks (NULL, &vf, (char*) data, size, callbacks)) | 85 | callbacks.seek_func = NULL; |
93 | { | 86 | callbacks.close_func = NULL; |
94 | ov_clear (&vf); | 87 | callbacks.tell_func = NULL; |
95 | return 0; | 88 | if (0 != ov_open_callbacks (plugin, &vf, NULL, 0, callbacks)) |
96 | } | 89 | { |
90 | ov_clear (&vf); | ||
91 | return 1; | ||
92 | } | ||
97 | comments = ov_comment (&vf, -1); | 93 | comments = ov_comment (&vf, -1); |
98 | if (NULL == comments) | 94 | if (NULL == comments) |
99 | { | 95 | { |
100 | ov_clear (&vf); | 96 | ov_clear (&vf); |
101 | return 0; | 97 | return 1; |
102 | } | 98 | } |
103 | ret = 0; | 99 | ret = 0; |
104 | ADD (EXTRACTOR_METATYPE_MIMETYPE, "application/ogg"); | 100 | ADD (EXTRACTOR_METATYPE_MIMETYPE, "application/ogg"); |
105 | if ((comments->vendor != NULL) && (strlen (comments->vendor) > 0)) | 101 | if ((comments->vendor != NULL) && (strlen (comments->vendor) > 0)) |
@@ -121,7 +117,7 @@ EXTRACTOR_ogg_extract (const char *data, | |||
121 | ADDG (EXTRACTOR_METATYPE_COPYRIGHT, "copyright"); | 117 | ADDG (EXTRACTOR_METATYPE_COPYRIGHT, "copyright"); |
122 | ADDG (EXTRACTOR_METATYPE_LICENSE, "license"); | 118 | ADDG (EXTRACTOR_METATYPE_LICENSE, "license"); |
123 | ADDG (EXTRACTOR_METATYPE_SONG_VERSION, "version"); | 119 | ADDG (EXTRACTOR_METATYPE_SONG_VERSION, "version"); |
124 | FINISH: | 120 | FINISH: |
125 | ov_clear (&vf); | 121 | ov_clear (&vf); |
126 | return ret; | 122 | return 1; |
127 | } | 123 | } |