libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 2d04cab5887474714c43ff39516e85ebf1a2fcce
parent 508fe889b1e71b2ba1c2d277cbdef6f52f0f1e64
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  3 May 2012 11:25:57 +0000

-LRN: port ogg extractor

Diffstat:
Mdoc/version.texi | 4++--
Msrc/plugins/Makefile.am | 10++++++++++
Msrc/plugins/ogg_extractor.c | 84++++++++++++++++++++++++++++++++++++++-----------------------------------------
3 files changed, 52 insertions(+), 46 deletions(-)

diff --git a/doc/version.texi b/doc/version.texi @@ -1,4 +1,4 @@ -@set UPDATED 29 January 2012 -@set UPDATED-MONTH January 2012 +@set UPDATED 21 March 2012 +@set UPDATED-MONTH March 2012 @set EDITION 0.6.3 @set VERSION 0.6.3 diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am @@ -16,6 +16,7 @@ plugin_LTLIBRARIES = \ libextractor_id3v2.la \ libextractor_ebml.la \ libextractor_s3m.la \ + libextractor_ogg.la \ libextractor_mp3.la libextractor_mp3_la_SOURCES = \ @@ -58,4 +59,13 @@ libextractor_s3m_la_LIBADD = \ $(top_builddir)/src/main/libextractor.la \ $(top_builddir)/src/common/libextractor_common.la +libextractor_ogg_la_SOURCES = \ + ogg_extractor.c +libextractor_ogg_la_LDFLAGS = \ + $(PLUGINFLAGS) +libextractor_ogg_la_LIBADD = \ + $(top_builddir)/src/main/libextractor.la \ + $(top_builddir)/src/common/libextractor_common.la \ + -lvorbisfile -lvorbis $(vorbisflag) -logg + EXTRA_DIST = template_extractor.c diff --git a/src/plugins/ogg_extractor.c b/src/plugins/ogg_extractor.c @@ -20,6 +20,7 @@ #include "platform.h" #include "extractor.h" +#include "extractor_plugins.h" #define DEBUG_EXTRACT_OGG 0 #define OGG_HEADER 0x4f676753 @@ -40,27 +41,21 @@ get_comment (vorbis_comment * vc, char *label) } static size_t -readError (void *ptr, size_t size, size_t nmemb, void *datasource) +readOgg (void *ptr, size_t size, size_t nmemb, void *datasource) { - return -1; -} - -static int -seekError (void *datasource, int64_t offset, int whence) -{ - return -1; -} - -static int -closeOk (void *datasource) -{ - return 0; -} + struct EXTRACTOR_PluginList *plugin = datasource; + int64_t ret; + unsigned char *read_data; -static long -tellError (void *datasource) -{ - return -1; + ret = pl_read (plugin, &read_data, size*nmemb); + if (ret <= 0) + { + if (ret < 0) + errno = EIO; + return 0; + } + memcpy (ptr, read_data, ret); + return ret; } #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) #define ADDG(t,d) do { m = get_comment (comments, d); if (m != NULL) ADD(t,m); } while (0) /* mimetype = application/ogg */ -int -EXTRACTOR_ogg_extract (const char *data, - size_t size, - EXTRACTOR_MetaDataProcessor proc, - void *proc_cls, - const char *options) +int +EXTRACTOR_ogg_extract_method (struct EXTRACTOR_PluginList *plugin, + EXTRACTOR_MetaDataProcessor proc, void *proc_cls) { OggVorbis_File vf; vorbis_comment *comments; ov_callbacks callbacks; int ret; + int64_t fsize; const char *m; - if (size < 2 * sizeof (int)) - return 0; - if (OGG_HEADER != ntohl (*(int *) data)) - return 0; - callbacks.read_func = &readError; - callbacks.seek_func = &seekError; - callbacks.close_func = &closeOk; - callbacks.tell_func = &tellError; - if (0 != ov_open_callbacks (NULL, &vf, (char*) data, size, callbacks)) - { - ov_clear (&vf); - return 0; - } + fsize = pl_get_fsize (plugin); + if (fsize > 0 && fsize < 2 * sizeof (int)) + return 1; + if (fsize == 0) + return 1; + + /* TODO: rewrite pl_seek() to be STDIO-compatible (SEEK_END) and enable seeking. */ + callbacks.read_func = &readOgg; + callbacks.seek_func = NULL; + callbacks.close_func = NULL; + callbacks.tell_func = NULL; + if (0 != ov_open_callbacks (plugin, &vf, NULL, 0, callbacks)) + { + ov_clear (&vf); + return 1; + } comments = ov_comment (&vf, -1); if (NULL == comments) - { - ov_clear (&vf); - return 0; - } + { + ov_clear (&vf); + return 1; + } ret = 0; ADD (EXTRACTOR_METATYPE_MIMETYPE, "application/ogg"); if ((comments->vendor != NULL) && (strlen (comments->vendor) > 0)) @@ -121,7 +117,7 @@ EXTRACTOR_ogg_extract (const char *data, ADDG (EXTRACTOR_METATYPE_COPYRIGHT, "copyright"); ADDG (EXTRACTOR_METATYPE_LICENSE, "license"); ADDG (EXTRACTOR_METATYPE_SONG_VERSION, "version"); - FINISH: +FINISH: ov_clear (&vf); - return ret; + return 1; }