gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21240 - in Extractor: doc src/plugins


From: gnunet
Subject: [GNUnet-SVN] r21240 - in Extractor: doc src/plugins
Date: Thu, 3 May 2012 13:25:57 +0200

Author: grothoff
Date: 2012-05-03 13:25:57 +0200 (Thu, 03 May 2012)
New Revision: 21240

Modified:
   Extractor/doc/version.texi
   Extractor/src/plugins/Makefile.am
   Extractor/src/plugins/ogg_extractor.c
Log:
-LRN: port ogg extractor

Modified: Extractor/doc/version.texi
===================================================================
--- Extractor/doc/version.texi  2012-05-03 11:11:26 UTC (rev 21239)
+++ Extractor/doc/version.texi  2012-05-03 11:25:57 UTC (rev 21240)
@@ -1,4 +1,4 @@
address@hidden UPDATED 29 January 2012
address@hidden UPDATED-MONTH January 2012
address@hidden UPDATED 21 March 2012
address@hidden UPDATED-MONTH March 2012
 @set EDITION 0.6.3
 @set VERSION 0.6.3

Modified: Extractor/src/plugins/Makefile.am
===================================================================
--- Extractor/src/plugins/Makefile.am   2012-05-03 11:11:26 UTC (rev 21239)
+++ Extractor/src/plugins/Makefile.am   2012-05-03 11:25:57 UTC (rev 21240)
@@ -16,6 +16,7 @@
   libextractor_id3v2.la \
   libextractor_ebml.la \
   libextractor_s3m.la \
+  libextractor_ogg.la \
   libextractor_mp3.la
 
 libextractor_mp3_la_SOURCES = \
@@ -58,4 +59,13 @@
   $(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 

Modified: Extractor/src/plugins/ogg_extractor.c
===================================================================
--- Extractor/src/plugins/ogg_extractor.c       2012-05-03 11:11:26 UTC (rev 
21239)
+++ Extractor/src/plugins/ogg_extractor.c       2012-05-03 11:25:57 UTC (rev 
21240)
@@ -20,6 +20,7 @@
 
 #include "platform.h"
 #include "extractor.h"
+#include "extractor_plugins.h"
 
 #define DEBUG_EXTRACT_OGG 0
 #define OGG_HEADER 0x4f676753
@@ -40,66 +41,61 @@
 }
 
 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;
-}
+  struct EXTRACTOR_PluginList *plugin = datasource;
+  int64_t ret;
+  unsigned char *read_data;
 
-static int
-seekError (void *datasource, int64_t offset, int whence)
-{
-  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;
 }
 
-static int
-closeOk (void *datasource)
-{
-  return 0;
-}
-
-static long
-tellError (void *datasource)
-{
-  return -1;
-}
-
 #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)
 
 #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 @@
   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;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]