libextractor

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

commit d66045bbd46390ef9e1bc973455f1baaa448f22f
parent 6f15c520ee8390e07039a7089a5d83434cddfdd4
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun,  5 Aug 2012 22:42:00 +0000

porting FLAC code to new API

Diffstat:
Msrc/plugins/Makefile.am | 28+++++++++++++++++++++++++---
Msrc/plugins/flac_extractor.c | 31++++++++++++++++++++-----------
Asrc/plugins/test_flac.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/testdata/flac_kraftwerk.flac | 0
Dtest/kraftwerk1.flac | 0
Dtest/test.rpm | 0
6 files changed, 122 insertions(+), 14 deletions(-)

diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am @@ -14,7 +14,8 @@ SUBDIRS = . EXTRA_DIST = template_extractor.c \ testdata/ogg_courseclear.ogg \ testdata/gif_image.gif \ - testdata/rpm_test.rpm + testdata/rpm_test.rpm \ + testdata/flac_kraftwerk.flac if HAVE_VORBISFILE PLUGIN_OGG=libextractor_ogg.la @@ -36,11 +37,17 @@ PLUGIN_RPM=libextractor_rpm.la TEST_RPM=test_rpm endif +if HAVE_FLAC +PLUGIN_FLAC=libextractor_flac.la +TEST_FLAC=test_flac +endif + plugin_LTLIBRARIES = \ $(PLUGIN_OGG) \ $(PLUGIN_MIME) \ $(PLUGIN_GIF) \ - $(PLUGIN_RPM) + $(PLUGIN_RPM) \ + $(PLUGIN_FLAC) if HAVE_ZZUF fuzz_tests=fuzz_default.sh @@ -50,7 +57,8 @@ check_PROGRAMS = \ $(TEST_OGG) \ $(TEST_MIME) \ $(TEST_GIF) \ - $(TEST_RPM) + $(TEST_RPM) \ + $(TEST_FLAC) TESTS = \ $(fuzz_tests) \ @@ -66,6 +74,7 @@ libtest_la_LIBADD = \ $(top_builddir)/src/main/libextractor.la + libextractor_ogg_la_SOURCES = \ ogg_extractor.c libextractor_ogg_la_LDFLAGS = \ @@ -122,4 +131,17 @@ test_rpm_LDADD = \ $(top_builddir)/src/plugins/libtest.la +libextractor_flac_la_SOURCES = \ + flac_extractor.c +libextractor_flac_la_LDFLAGS = \ + $(PLUGINFLAGS) +libextractor_flac_la_LIBADD = \ + $(top_builddir)/src/main/libextractor.la \ + -lFLAC + +test_flac_SOURCES = \ + test_flac.c +test_flac_LDADD = \ + $(top_builddir)/src/plugins/libtest.la + diff --git a/src/plugins/flac_extractor.c b/src/plugins/flac_extractor.c @@ -217,9 +217,12 @@ static struct Matches tmap[] = { /** - * FIXME. + * Give meta data to extractor. + * + * @param t type of the meta data + * @param s meta data value in utf8 format */ -#define ADD (t,s) do { if (ctx->ret == 0) ctx->ret = ctx->proc (ctx->proc_cls, "flac", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1); } while (0) +#define ADD(t,s) do { ec->proc (ec->cls, "flac", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1); } while (0) /** @@ -235,7 +238,7 @@ xstrndup (const char *s, { char * d; - if (NULL == (d = malloc(n+1))) + if (NULL == (d = malloc (n + 1))) return NULL; memcpy (d, s, n); d[n] = '\0'; @@ -244,7 +247,14 @@ xstrndup (const char *s, /** - * FIXME. + * Check if a mapping exists for the given meta data value + * and if so give the result to LE. + * + * @param type type of the meta data according to FLAC + * @param type_length number of bytes in 'type' + * @param value meta data as UTF8 string (non 0-terminated) + * @param value_length number of bytes in value + * @param ec extractor context */ static void check (const char *type, @@ -269,6 +279,7 @@ check (const char *type, continue; ADD (tmap[i].type, tmp); free (tmp); + break; } } @@ -293,12 +304,12 @@ flac_metadata (const FLAC__StreamDecoder *decoder, const char * eq; unsigned int len; unsigned int ilen; - + char buf[128]; + switch (metadata->type) { case FLAC__METADATA_TYPE_STREAMINFO: { - char buf[512]; snprintf (buf, sizeof (buf), _("%u Hz, %u channels"), metadata->data.stream_info.sample_rate, @@ -322,7 +333,7 @@ flac_metadata (const FLAC__StreamDecoder *decoder, eq = (const char*) entry->entry; len = entry->length; ilen = 0; - while ( ('=' != *eq) && (*eq != '\0') && + while ( ('=' != *eq) && ('\0' != *eq) && (ilen < len) ) { eq++; @@ -336,14 +347,12 @@ flac_metadata (const FLAC__StreamDecoder *decoder, ilen, eq, len - ilen, - ctx); + ec); } break; } case FLAC__METADATA_TYPE_PICTURE: { - if (0 != ctx->ret) - break; switch (metadata->data.picture.type) { case FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER: @@ -387,7 +396,7 @@ flac_metadata (const FLAC__StreamDecoder *decoder, EXTRACTOR_METAFORMAT_BINARY, metadata->data.picture.mime_type, (const char*) metadata->data.picture.data, - metadata->data.picture.data_length)) + metadata->data.picture.data_length); break; } case FLAC__METADATA_TYPE_PADDING: diff --git a/src/plugins/test_flac.c b/src/plugins/test_flac.c @@ -0,0 +1,77 @@ +/* + This file is part of libextractor. + (C) 2012 Vidyut Samanta and Christian Grothoff + + libextractor is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + libextractor is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libextractor; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file plugins/test_flac.c + * @brief testcase for flac plugin + * @author Christian Grothoff + */ +#include "platform.h" +#include "test_lib.h" + + + +/** + * Main function for the FLAC testcase. + * + * @param argc number of arguments (ignored) + * @param argv arguments (ignored) + * @return 0 on success + */ +int +main (int argc, char *argv[]) +{ + struct SolutionData kraftwerk_sol[] = + { + { + EXTRACTOR_METATYPE_MIMETYPE, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + "audio/flac", + strlen ("audio/flac") + 1, + 0 + }, + { + EXTRACTOR_METATYPE_RESOURCE_TYPE, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + "44100 Hz, 2 channels", + strlen ("44100 Hz, 2 channels") + 1, + 0 + }, + { + EXTRACTOR_METATYPE_TITLE, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + "Test Title", + strlen ("Test Title") + 1, + 0 + }, + { 0, 0, NULL, NULL, 0, -1 } + }; + struct ProblemSet ps[] = + { + { "testdata/flac_kraftwerk.flac", + kraftwerk_sol }, + { NULL, NULL } + }; + return ET_main ("flac", ps); +} + +/* end of test_flac.c */ diff --git a/src/plugins/testdata/flac_kraftwerk.flac b/src/plugins/testdata/flac_kraftwerk.flac Binary files differ. diff --git a/test/kraftwerk1.flac b/test/kraftwerk1.flac Binary files differ. diff --git a/test/test.rpm b/test/test.rpm Binary files differ.