Add audio-dummy with missing audio formats.
authorbarbieri <barbieri@gmail.com>
Fri, 21 Dec 2007 14:44:41 +0000 (14:44 +0000)
committerbarbieri <barbieri@gmail.com>
Fri, 21 Dec 2007 14:44:41 +0000 (14:44 +0000)
lightmediascanner/configure.ac
lightmediascanner/src/plugins/audio-dummy/Makefile.am [new file with mode: 0644]
lightmediascanner/src/plugins/audio-dummy/audio-dummy.c [new file with mode: 0644]

index 8b613e1..80e590c 100644 (file)
@@ -57,6 +57,7 @@ AC_LMS_OPTIONAL_MODULE([dummy], true)
 AC_LMS_OPTIONAL_MODULE([jpeg], true)
 AC_LMS_OPTIONAL_MODULE([id3lib], true, [CHECK_MODULE_ID3LIB])
 AC_LMS_OPTIONAL_MODULE([video-dummy], true)
+AC_LMS_OPTIONAL_MODULE([audio-dummy], true)
 AC_LMS_OPTIONAL_MODULE([m3u], true)
 AC_LMS_OPTIONAL_MODULE([ogg], true, [CHECK_MODULE_OGG])
 AC_LMS_OPTIONAL_MODULE([pls], true)
@@ -73,6 +74,7 @@ src/plugins/dummy/Makefile
 src/plugins/jpeg/Makefile
 src/plugins/id3lib/Makefile
 src/plugins/video-dummy/Makefile
+src/plugins/audio-dummy/Makefile
 src/plugins/m3u/Makefile
 src/plugins/ogg/Makefile
 src/plugins/pls/Makefile
diff --git a/lightmediascanner/src/plugins/audio-dummy/Makefile.am b/lightmediascanner/src/plugins/audio-dummy/Makefile.am
new file mode 100644 (file)
index 0000000..23667ce
--- /dev/null
@@ -0,0 +1,10 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_srcdir)/src/plugins/audio-dummy
+
+pkgdir = $(pluginsdir)
+pkg_LTLIBRARIES = audio-dummy.la
+audio_dummy_la_SOURCES = audio-dummy.c
+audio_dummy_la_DEPENDENCIES = $(top_builddir)/config.h
+audio_dummy_la_LIBADD = $(top_builddir)/src/lib/liblightmediascanner.la
+audio_dummy_la_LDFLAGS = -module -avoid-version
diff --git a/lightmediascanner/src/plugins/audio-dummy/audio-dummy.c b/lightmediascanner/src/plugins/audio-dummy/audio-dummy.c
new file mode 100644 (file)
index 0000000..3537374
--- /dev/null
@@ -0,0 +1,133 @@
+/**
+ * Copyright (C) 2007 by INdT
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
+ */
+
+/**
+ * @brief
+ *
+ * Audio Dummy plugin, just register matched extensions in audios DB.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _XOPEN_SOURCE 600
+#include <lightmediascanner_plugin.h>
+#include <lightmediascanner_db.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static const char _name[] = "audio-dummy";
+static const struct lms_string_size _exts[] = {
+    LMS_STATIC_STRING_SIZE(".m4a"),
+    LMS_STATIC_STRING_SIZE(".aac"),
+    LMS_STATIC_STRING_SIZE(".ra"),
+    LMS_STATIC_STRING_SIZE(".wma"),
+    LMS_STATIC_STRING_SIZE(".wav")
+};
+
+struct plugin {
+    struct lms_plugin plugin;
+    lms_db_audio_t *audio_db;
+};
+
+static void *
+_match(struct plugin *p, const char *path, int len, int base)
+{
+    int i;
+
+    i = lms_which_extension(path, len, _exts, LMS_ARRAY_SIZE(_exts));
+    if (i < 0)
+        return NULL;
+    else
+        return (void*)(i + 1);
+}
+
+static int
+_parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_info *finfo, void *match)
+{
+    struct lms_audio_info info = {0};
+    int r, ext_idx;
+
+    ext_idx = ((int)match) - 1;
+    info.title.len = finfo->path_len - finfo->base - _exts[ext_idx].len;
+    info.title.str = malloc((info.title.len + 1) * sizeof(char));
+    memcpy(info.title.str, finfo->path + finfo->base, info.title.len);
+    info.title.str[info.title.len] = '\0';
+    lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
+
+    info.id = finfo->id;
+    r = lms_db_audio_add(plugin->audio_db, &info);
+
+    free(info.title.str);
+
+    return r;
+}
+
+static int
+_setup(struct plugin *plugin, struct lms_context *ctxt)
+{
+    plugin->audio_db = lms_db_audio_new(ctxt->db);
+    if (!plugin->audio_db)
+        return -1;
+
+    return 0;
+}
+
+static int
+_start(struct plugin *plugin, struct lms_context *ctxt)
+{
+    return lms_db_audio_start(plugin->audio_db);
+}
+
+static int
+_finish(struct plugin *plugin, struct lms_context *ctxt)
+{
+    if (plugin->audio_db)
+        return lms_db_audio_free(plugin->audio_db);
+
+    return 0;
+}
+
+
+static int
+_close(struct plugin *plugin)
+{
+    free(plugin);
+    return 0;
+}
+
+API struct lms_plugin *
+lms_plugin_open(void)
+{
+    struct plugin *plugin;
+
+    plugin = malloc(sizeof(*plugin));
+    plugin->plugin.name = _name;
+    plugin->plugin.match = (lms_plugin_match_fn_t)_match;
+    plugin->plugin.parse = (lms_plugin_parse_fn_t)_parse;
+    plugin->plugin.close = (lms_plugin_close_fn_t)_close;
+    plugin->plugin.setup = (lms_plugin_setup_fn_t)_setup;
+    plugin->plugin.start = (lms_plugin_start_fn_t)_start;
+    plugin->plugin.finish = (lms_plugin_finish_fn_t)_finish;
+
+    return (struct lms_plugin *)plugin;
+}