/**
+ * Copyright (C) 2008-2011 by ProFUSION embedded systems
* Copyright (C) 2007 by INdT
*
- * This program is free software; you can redistribute it and/or
+ * This library 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.
+ * as published by the Free Software Foundation; either version 2.1 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.
+ * This library 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
+ * Lesser 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
*
- * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
+ * @author Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
*/
/**
*
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#define _XOPEN_SOURCE 600
#include <lightmediascanner_plugin.h>
#include <lightmediascanner_utils.h>
#include <lightmediascanner_db.h>
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <strings.h>
+static const struct lms_string_size dlna_mime =
+ LMS_STATIC_STRING_SIZE("image/png");
+static const struct lms_string_size dlna_sm_ico =
+ LMS_STATIC_STRING_SIZE("PNG_SM_ICO");
+static const struct lms_string_size dlna_lrg_ico =
+ LMS_STATIC_STRING_SIZE("PNG_LRG_ICO");
+static const struct lms_string_size dlna_tn =
+ LMS_STATIC_STRING_SIZE("PNG_TN");
+static const struct lms_string_size dlna_lrg =
+ LMS_STATIC_STRING_SIZE("PNG_LRG");
+
+static void
+_fill_dlna_profile(struct lms_image_info *info)
+{
+ const unsigned short w = info->width;
+ const unsigned short h = info->height;
+
+ info->dlna_mime = dlna_mime;
+
+ if (w == 0 || h == 0)
+ return;
+
+ if (w == 48 && h == 48)
+ info->dlna_profile = dlna_sm_ico;
+ else if (w == 120 && h == 120)
+ info->dlna_profile = dlna_lrg_ico;
+ else if (w <= 160 && h <= 160)
+ info->dlna_profile = dlna_tn;
+ else if (w <= 4096 && h <= 4096)
+ info->dlna_profile = dlna_lrg;
+}
+
static inline unsigned int
_chunk_to_uint(unsigned char *buf)
{
static const struct lms_string_size _exts[] = {
LMS_STATIC_STRING_SIZE(".png")
};
+static const char *_cats[] = {
+ "multimedia",
+ "picture",
+ NULL
+};
+static const char *_authors[] = {
+ "Gustavo Sverzut Barbieri",
+ NULL
+};
struct plugin {
struct lms_plugin plugin;
static void *
_match(struct plugin *p, const char *path, int len, int base)
{
- int i;
+ long i;
i = lms_which_extension(path, len, _exts, LMS_ARRAY_SIZE(_exts));
if (i < 0)
static int
_parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_info *finfo, void *match)
{
- struct lms_image_info info = {0};
+ struct lms_image_info info = { };
int fd, r;
fd = open(finfo->path, O_RDONLY);
if (info.date == 0)
info.date = finfo->mtime;
- if (!info.title.str) {
- int 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';
- }
-
+ if (!info.title.str)
+ lms_name_from_path(&info.title, finfo->path, finfo->path_len,
+ finfo->base, _exts[((long) match) - 1].len,
+ NULL);
if (info.title.str)
- lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
+ lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
if (info.artist.str)
lms_charset_conv(ctxt->cs_conv, &info.artist.str, &info.artist.len);
+ _fill_dlna_profile(&info);
+
info.id = finfo->id;
r = lms_db_image_add(plugin->img_db, &info);
done:
- if (info.title.str)
- free(info.title.str);
- if (info.artist.str)
- free(info.artist.str);
+ free(info.title.str);
+ free(info.artist.str);
posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
close(fd);
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;
+ plugin->plugin.order = 0;
return (struct lms_plugin *)plugin;
}
+
+API const struct lms_plugin_info *
+lms_plugin_info(void)
+{
+ static struct lms_plugin_info info = {
+ _name,
+ _cats,
+ "PNG images",
+ PACKAGE_VERSION,
+ _authors,
+ "http://github.com/profusion/lightmediascanner"
+ };
+
+ return &info;
+}