[maemo-commits] [maemo-commits] r16653 - in projects/haf/trunk/hildon-thumbnail: . daemon daemon/plugins
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu Nov 13 13:45:34 EET 2008
- Previous message: [maemo-commits] r16652 - projects/haf/tags/totem-pl-parser
- Next message: [maemo-commits] r16654 - projects/haf/trunk/hildon-thumbnail/daemon/plugins
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2008-11-13 13:45:30 +0200 (Thu, 13 Nov 2008) New Revision: 16653 Added: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-jpeg-out-plugin.c Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog projects/haf/trunk/hildon-thumbnail/daemon/Makefile.am projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h projects/haf/trunk/hildon-thumbnail/daemon/plugins/Makefile.am projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c Log: 2008-11-13 Philip Van Hoof <philip at codeminded.be> * daemon/hildon-thumbnail-plugin.h * daemon/hildon-thumbnail-daemon.c * daemon/plugins/gdkpixbuf-jpeg-out-plugin.c * daemon/plugins/gdkpixbuf-plugin.c * daemon/plugins/Makefile.am * daemon/plugins/gstreamer-video-plugin.c * daemon/plugins/epeg-plugin.c * daemon/thumbnailer.c * daemon/Makefile.am * daemon/hildon-thumbnail-plugin.c: Output plugins Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog =================================================================== --- projects/haf/trunk/hildon-thumbnail/ChangeLog 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/ChangeLog 2008-11-13 11:45:30 UTC (rev 16653) @@ -1,3 +1,16 @@ +2008-11-13 Philip Van Hoof <philip at codeminded.be> + + * daemon/hildon-thumbnail-plugin.h + * daemon/hildon-thumbnail-daemon.c + * daemon/plugins/gdkpixbuf-jpeg-out-plugin.c + * daemon/plugins/gdkpixbuf-plugin.c + * daemon/plugins/Makefile.am + * daemon/plugins/gstreamer-video-plugin.c + * daemon/plugins/epeg-plugin.c + * daemon/thumbnailer.c + * daemon/Makefile.am + * daemon/hildon-thumbnail-plugin.c: Output plugins + 2008-11-07 Marius Vollmer <marius.vollmer at nokia.com> Released 3.0.9. Modified: projects/haf/trunk/hildon-thumbnail/daemon/Makefile.am =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/Makefile.am 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/Makefile.am 2008-11-13 11:45:30 UTC (rev 16653) @@ -7,7 +7,8 @@ $(GIO_CFLAGS) \ -DTHUMBNAILERS_DIR=\""/usr/share/thumbnailers"\" \ -DALBUMARTERS_DIR=\""/usr/share/albumart-providers"\" \ - -DPLUGINS_DIR=\""$(libdir)/hildon-thumbnailer/plugins"\" + -DPLUGINS_DIR=\""$(libdir)/hildon-thumbnailer/plugins"\" \ + -DOUTPUTPLUGINS_DIR=\""$(libdir)/hildon-thumbnailer/output-plugins"\" noinst_LTLIBRARIES = libshared.la Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c 2008-11-13 11:45:30 UTC (rev 16653) @@ -35,6 +35,7 @@ #include "albumart-manager.h" static GHashTable *registrations; +static GHashTable *outregistrations; static gboolean do_shut_down_next_time = TRUE; void @@ -98,9 +99,48 @@ g_dir_close (dir); } + if (error) + g_error_free (error); + return regs; } + +static GHashTable* +init_outputplugins (DBusGConnection *connection, Thumbnailer *thumbnailer) +{ + GHashTable *regs; + GModule *module; + GError *error = NULL; + GDir *dir; + const gchar *plugin; + + regs = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) NULL); + + dir = g_dir_open (OUTPUTPLUGINS_DIR, 0, &error); + + if (dir) { + while ((plugin = g_dir_read_name (dir)) != NULL) { + + if (!g_str_has_suffix (plugin, "." G_MODULE_SUFFIX)) { + continue; + } + + module = hildon_thumbnail_outplugin_load (plugin); + g_hash_table_replace (regs, g_strdup (plugin), + module); + } + g_dir_close (dir); + } + + if (error) + g_error_free (error); + + return regs; +} + static void stop_plugins (GHashTable *regs, Thumbnailer *thumbnailer) { @@ -115,7 +155,18 @@ } } +static void +stop_outputplugins (GHashTable *regs, Thumbnailer *thumbnailer) +{ + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init (&iter, regs); + + while (g_hash_table_iter_next (&iter, &key, &value)) { + } +} + static void on_plugin_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { @@ -161,6 +212,35 @@ } + +static void +on_outputplugin_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) +{ + Thumbnailer *thumbnailer = user_data; + gchar *path = g_file_get_path (other_file); + + if (path) { + switch (event_type) { + case G_FILE_MONITOR_EVENT_DELETED: { + GModule *module = g_hash_table_lookup (outregistrations, path); + if (module) { + } + } + case G_FILE_MONITOR_EVENT_CREATED: { + GModule *module = hildon_thumbnail_outplugin_load (path); + g_hash_table_replace (outregistrations, g_strdup (path), + module); + } + break; + default: + break; + } + } + + g_free (path); +} + + int main (int argc, char **argv) { @@ -200,12 +280,18 @@ MANAGER_INTERFACE); registrations = init_plugins (connection, thumbnailer); + outregistrations = init_outputplugins (connection, thumbnailer); file = g_file_new_for_path (PLUGINS_DIR); monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); g_signal_connect (G_OBJECT (monitor), "changed", G_CALLBACK (on_plugin_changed), thumbnailer); + file = g_file_new_for_path (OUTPUTPLUGINS_DIR); + monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_signal_connect (G_OBJECT (monitor), "changed", + G_CALLBACK (on_outputplugin_changed), thumbnailer); + main_loop = g_main_loop_new (NULL, FALSE); g_timeout_add_seconds (600, @@ -218,6 +304,7 @@ g_object_unref (file); stop_plugins (registrations, thumbnailer); + stop_outputplugins (outregistrations, thumbnailer); g_hash_table_unref (registrations); Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c 2008-11-13 11:45:30 UTC (rev 16653) @@ -24,7 +24,93 @@ #include "hildon-thumbnail-plugin.h" +static GList *outplugs = NULL; +typedef gboolean (*IsActiveFunc) (void); + +GModule* +hildon_thumbnail_outplugin_load (const gchar *module_name) +{ + gchar *path; + GModule *module; + + g_return_val_if_fail (module_name != NULL, NULL); + + path = g_build_filename (OUTPUTPLUGINS_DIR, module_name, NULL); + + module = g_module_open (path, G_MODULE_BIND_LOCAL); + + if (!module) { + g_warning ("Could not load thumbnailer module '%s', %s\n", + module_name, + g_module_error ()); + } else { + IsActiveFunc isac_func; + + if (g_module_symbol (module, "hildon_thumbnail_outplugin_is_active", (gpointer *) &isac_func)) { + if (isac_func ()) { + outplugs = g_list_prepend (outplugs, module); + g_module_make_resident (module); + } + } + } + + g_free (path); + + return module; +} + +typedef void (*OutFunc) (const guchar *rgb8_pixmap, + guint width, guint height, + guint rowstride, + OutType type, + guint64 mtime, + const gchar *uri, + GError **error); + +void +hildon_thumbnail_outplugins_do_out (const guchar *rgb8_pixmap, + guint width, guint height, + guint rowstride, + OutType type, + guint64 mtime, + const gchar *uri, + GError **error) +{ + GList *copy = outplugs; + GString *errors = NULL; + GQuark domain; + + while (copy) { + GModule *module = copy->data; + OutFunc out_func; + GError *nerror = NULL; + + if (g_module_symbol (module, "hildon_thumbnail_outplugin_out", (gpointer *) &out_func)) { + + out_func (rgb8_pixmap, width, height, rowstride, type, mtime, uri, &nerror); + + if (nerror) { + if (!errors) { + errors = g_string_new (""); + domain = nerror->domain; + } + g_string_append (errors, nerror->message); + g_error_free (nerror); + } + + } + copy = g_list_next (copy); + } + + if (errors) { + g_set_error (error, domain, 0, errors->str); + g_string_free (errors, TRUE); + } +} + + + GModule * hildon_thumbnail_plugin_load (const gchar *module_name) { Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h 2008-11-13 11:45:30 UTC (rev 16653) @@ -31,6 +31,12 @@ G_BEGIN_DECLS +typedef enum { + OUTTYPE_LARGE, + OUTTYPE_NORMAL, + OUTTYPE_CROPPED, +} OutType; + typedef void (*register_func) (gpointer self, const gchar *mime_type, GModule *module, const GStrv uri_schemes, gint priority); GModule * hildon_thumbnail_plugin_load (const gchar *module_name); @@ -47,6 +53,16 @@ GError **error); void hildon_thumbnail_plugin_do_stop (GModule *module); + +GModule* hildon_thumbnail_outplugin_load (const gchar *module_name); +void hildon_thumbnail_outplugins_do_out (const guchar *rgb8_pixmap, + guint width, guint height, + guint rowstride, + OutType type, + guint64 mtime, + const gchar *uri, + GError **error); + G_END_DECLS #endif Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/Makefile.am =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/Makefile.am 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/Makefile.am 2008-11-13 11:45:30 UTC (rev 16653) @@ -1,6 +1,10 @@ plugin_flags = -module -avoid-version -no-undefined pluginsdir = $(libdir)/hildon-thumbnailer/plugins +outputpluginsdir = $(libdir)/hildon-thumbnailer/output-plugins + +outputplugins_LTLIBRARIES = libhildon-thumbnailer-jpeg.la + plugins_LTLIBRARIES = libhildon-thumbnailer-gdkpixbuf.la \ libhildon-thumbnailer-exec.la @@ -26,6 +30,11 @@ $(GLIB_LIBS) \ $(GDK_PIXBUF_LIBS) +libhildon_thumbnailer_jpeg_la_SOURCES = gdkpixbuf-jpeg-out-plugin.c +libhildon_thumbnailer_jpeg_la_LDFLAGS = $(plugin_flags) +libhildon_thumbnailer_jpeg_la_CFLAGS = $(libhildon_thumbnailer_gdkpixbuf_la_CFLAGS) +libhildon_thumbnailer_jpeg_la_LIBADD = $(libhildon_thumbnailer_gdkpixbuf_la_LIBADD) + libhildon_thumbnailer_exec_la_CFLAGS = \ -I. -I$(top_srcdir)/daemon \ -I$(top_srcdir)/thumbs \ Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c 2008-11-13 11:45:30 UTC (rev 16653) @@ -45,7 +45,6 @@ static gchar **supported = NULL; static gboolean do_cropped = TRUE; -static gboolean do_pngs = FALSE; static GFileMonitor *monitor = NULL; const gchar** @@ -67,54 +66,7 @@ #define MTIME_OPTION HILDON_THUMBNAIL_OPTION_PREFIX "MTime" #define SOFTWARE_OPTION "tEXt::Software" -static gboolean -save_thumb_file_meta (GdkPixbuf *pixbuf, gchar *file, guint64 mtime, const gchar *uri, GError **error) -{ - gboolean ret; - if (do_pngs) { - char mtime_str[64]; - - const char *default_keys[] = { - URI_OPTION, - MTIME_OPTION, - SOFTWARE_OPTION, - NULL - }; - - const char *default_values[] = { - uri, - mtime_str, - HILDON_THUMBNAIL_APPLICATION "-" VERSION, - NULL - }; - - g_sprintf(mtime_str, "%lu", mtime); - - ret = gdk_pixbuf_savev (pixbuf, file, "png", - (char **) default_keys, - (char **) default_values, - error); - } else { - ret = gdk_pixbuf_save (pixbuf, file, "jpeg", - error, NULL); - } - - return ret; -} - - - -static gboolean -save_thumb_file_cropped (GdkPixbuf *pixbuf, gchar *file, guint64 mtime, const gchar *uri, GError **error) -{ - gboolean ret; - - ret = gdk_pixbuf_save (pixbuf, file, "jpeg", error, NULL); - - return ret; -} - static GdkPixbuf* crop_resize (GdkPixbuf *src, int width, int height) { int x = width, y = height; @@ -209,32 +161,11 @@ GdkPixbuf *pixbuf_large = NULL, *pixbuf_normal, *pixbuf_cropped; - gchar *large = NULL, - *normal = NULL, - *cropped = NULL; guint64 mtime; - gboolean just_crop; GFileInfo *finfo = NULL; GError *nerror = NULL; guint ow, oh; - hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, - &cropped, - NULL, NULL, NULL, do_pngs); - - just_crop = (g_file_test (large, G_FILE_TEST_EXISTS) && - /* g_file_test (epeg, G_FILE_TEST_EXISTS) && */ - g_file_test (normal, G_FILE_TEST_EXISTS) && - !g_file_test (cropped, G_FILE_TEST_EXISTS)); - - if (just_crop && !do_cropped) { - g_free (cropped); - g_free (normal); - g_free (large); - /* g_free (epeg); */ - continue; - } - file = g_file_new_for_uri (uri); path = g_file_get_path (file); @@ -291,14 +222,28 @@ destroy_pixbuf, im); } - save_thumb_file_meta (pixbuf_large, large, mtime, uri, &nerror); + hildon_thumbnail_outplugins_do_out (gdk_pixbuf_get_pixels (pixbuf_large), + gdk_pixbuf_get_width (pixbuf_large), + gdk_pixbuf_get_height (pixbuf_large), + gdk_pixbuf_get_rowstride (pixbuf_large), + OUTTYPE_LARGE, + mtime, + uri, + &nerror); if (nerror) goto nerror_handler; pixbuf_cropped = crop_resize (pixbuf_large, 124, 124); - save_thumb_file_cropped (pixbuf_cropped, cropped, mtime, uri, &nerror); + hildon_thumbnail_outplugins_do_out (gdk_pixbuf_get_pixels (pixbuf_cropped), + gdk_pixbuf_get_width (pixbuf_cropped), + gdk_pixbuf_get_height (pixbuf_cropped), + gdk_pixbuf_get_rowstride (pixbuf_cropped), + OUTTYPE_CROPPED, + mtime, + uri, + &nerror); g_object_unref (pixbuf_cropped); @@ -309,7 +254,14 @@ 128, 128, GDK_INTERP_HYPER); - save_thumb_file_meta (pixbuf_normal, normal, mtime, uri, &nerror); + hildon_thumbnail_outplugins_do_out (gdk_pixbuf_get_pixels (pixbuf_normal), + gdk_pixbuf_get_width (pixbuf_normal), + gdk_pixbuf_get_height (pixbuf_normal), + gdk_pixbuf_get_rowstride (pixbuf_normal), + OUTTYPE_NORMAL, + mtime, + uri, + &nerror); g_object_unref (pixbuf_normal); @@ -343,10 +295,6 @@ g_object_unref (finfo); g_free (path); - /* g_free (epeg); */ - g_free (large); - g_free (normal); - g_free (cropped); i++; } @@ -399,16 +347,14 @@ if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) { do_cropped = TRUE; - do_pngs = FALSE; g_key_file_free (keyfile); return; } - do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", NULL); - do_pngs = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoPngs", &error); + do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", &error); if (error) { - do_pngs = FALSE; + do_cropped = TRUE; g_error_free (error); } Added: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-jpeg-out-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-jpeg-out-plugin.c 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-jpeg-out-plugin.c 2008-11-13 11:45:30 UTC (rev 16653) @@ -0,0 +1,148 @@ +/* + * This file is part of hildon-thumbnail package + * + * Copyright (C) 2005 Nokia Corporation. All Rights reserved. + * + * Contact: Marius Vollmer <marius.vollmer at nokia.com> + * Author: Philip Van Hoof <philip at codeminded.be> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> +#include <glib.h> +#include <gio/gio.h> +#include <dbus/dbus-glib-bindings.h> +#include <gdk-pixbuf/gdk-pixbuf.h> +#include <gdk-pixbuf/gdk-pixbuf-io.h> + +#include "utils.h" +#include "hildon-thumbnail-plugin.h" + +static gboolean had_init = FALSE; +static gboolean is_active = TRUE; + +void +hildon_thumbnail_outplugin_out (const guchar *rgb8_pixmap, + guint width, guint height, + guint rowstride, + OutType type, + guint64 mtime, + const gchar *uri, + GError **error) +{ + GdkPixbuf *pixbuf; + gchar *large, *normal, *cropped, *filen; + + hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped, + NULL, NULL, NULL, FALSE); + + switch (type) { + case OUTTYPE_LARGE: + filen = large; + break; + case OUTTYPE_NORMAL: + filen = normal; + break; + case OUTTYPE_CROPPED: + filen = cropped; + break; + } + + pixbuf = gdk_pixbuf_new_from_data ((const guchar*) rgb8_pixmap, + GDK_COLORSPACE_RGB, FALSE, + 8, width, height, rowstride, + NULL, NULL); + + gdk_pixbuf_save (pixbuf, filen, "jpeg", + error, NULL); + + g_object_unref (pixbuf); + + g_free (normal); + g_free (large); + g_free (cropped); + + return; +} + + + +static void +reload_config (const gchar *config) +{ + GKeyFile *keyfile; + GStrv mimetypes; + guint i = 0, length; + GError *error = NULL; + + keyfile = g_key_file_new (); + + if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) { + is_active = TRUE; + g_key_file_free (keyfile); + return; + } + + is_active = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "IsActive", &error); + + if (error) { + is_active = TRUE; + g_error_free (error); + } + + g_key_file_free (keyfile); +} + + +static void +on_file_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) +{ + if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT || event_type == G_FILE_MONITOR_EVENT_CREATED) { + gchar *config = g_file_get_path (file); + reload_config (config); + g_free (config); + } +} + +void +hildon_thumbnail_outplugin_is_active (void) +{ + if (!had_init) { + gchar *config = g_build_filename (g_get_user_config_dir (), "hildon-thumbnailer", "gdkpixbuf-output-plugin.conf", NULL); + GFile *file = g_file_new_for_path (config); + GFileMonitor *monitor; + + monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); + + g_signal_connect (G_OBJECT (monitor), "changed", + G_CALLBACK (on_file_changed), NULL); + + /* g_object_unref (monitor); */ + g_object_unref (file); + + reload_config (config); + + had_init = TRUE; + } + + return is_active; +} Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c 2008-11-13 11:45:30 UTC (rev 16653) @@ -58,7 +58,6 @@ static gchar **supported = NULL; static gboolean do_cropped = TRUE; -static gboolean do_pngs = FALSE; static GFileMonitor *monitor = NULL; const gchar** @@ -94,54 +93,8 @@ #define MTIME_OPTION HILDON_THUMBNAIL_OPTION_PREFIX "MTime" #define SOFTWARE_OPTION "tEXt::Software" -static gboolean -save_thumb_file_meta (GdkPixbuf *pixbuf, gchar *file, guint64 mtime, const gchar *uri, GError **error) -{ - gboolean ret; - if (do_pngs) { - char mtime_str[64]; - const char *default_keys[] = { - URI_OPTION, - MTIME_OPTION, - SOFTWARE_OPTION, - NULL - }; - const char *default_values[] = { - uri, - mtime_str, - HILDON_THUMBNAIL_APPLICATION "-" VERSION, - NULL - }; - - g_sprintf(mtime_str, "%lu", mtime); - - ret = gdk_pixbuf_savev (pixbuf, file, "png", - (char **) default_keys, - (char **) default_values, - error); - } else { - ret = gdk_pixbuf_save (pixbuf, file, "jpeg", - error, NULL); - } - - return ret; -} - - - -static gboolean -save_thumb_file_cropped (GdkPixbuf *pixbuf, gchar *file, guint64 mtime, const gchar *uri, GError **error) -{ - gboolean ret; - - ret = gdk_pixbuf_save (pixbuf, file, "jpeg", error, NULL); - - return ret; -} - - static GdkPixbuf* crop_resize (GdkPixbuf *src, int width, int height) { int x = width, y = height; @@ -228,25 +181,8 @@ GdkPixbuf *pixbuf_normal; GdkPixbuf *pixbuf, *pixbuf_cropped; guint64 mtime; - gchar *large = NULL, - *normal = NULL, - *cropped = NULL; - gboolean just_crop; - hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped, - NULL, NULL, NULL, do_pngs); - just_crop = (g_file_test (large, G_FILE_TEST_EXISTS) && - g_file_test (normal, G_FILE_TEST_EXISTS) && - !g_file_test (cropped, G_FILE_TEST_EXISTS)); - - if (just_crop && !do_cropped) { - g_free (cropped); - g_free (normal); - g_free (large); - continue; - } - file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, @@ -272,7 +208,14 @@ if (nerror) goto nerror_handler; - save_thumb_file_meta (pixbuf_large, large, mtime, uri, &nerror); + hildon_thumbnail_outplugins_do_out (gdk_pixbuf_get_pixels (pixbuf_large), + gdk_pixbuf_get_width (pixbuf_large), + gdk_pixbuf_get_height (pixbuf_large), + gdk_pixbuf_get_rowstride (pixbuf_large), + OUTTYPE_LARGE, + mtime, + uri, + &nerror); g_object_unref (pixbuf_large); @@ -293,7 +236,14 @@ if (nerror) goto nerror_handler; - save_thumb_file_meta (pixbuf_normal, normal, mtime, uri, &nerror); + hildon_thumbnail_outplugins_do_out (gdk_pixbuf_get_pixels (pixbuf_normal), + gdk_pixbuf_get_width (pixbuf_normal), + gdk_pixbuf_get_height (pixbuf_normal), + gdk_pixbuf_get_rowstride (pixbuf_normal), + OUTTYPE_NORMAL, + mtime, + uri, + &nerror); g_object_unref (pixbuf_normal); @@ -316,7 +266,14 @@ g_object_unref (pixbuf); - save_thumb_file_cropped (pixbuf_cropped, cropped, mtime, uri, &nerror); + hildon_thumbnail_outplugins_do_out (gdk_pixbuf_get_pixels (pixbuf_cropped), + gdk_pixbuf_get_width (pixbuf_cropped), + gdk_pixbuf_get_height (pixbuf_cropped), + gdk_pixbuf_get_rowstride (pixbuf_cropped), + OUTTYPE_CROPPED, + mtime, + uri, + &nerror); g_object_unref (pixbuf_cropped); @@ -343,9 +300,6 @@ if (file) g_object_unref (file); - g_free (large); - g_free (normal); - g_free (cropped); i++; } @@ -396,16 +350,14 @@ if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) { do_cropped = TRUE; - do_pngs = FALSE; g_key_file_free (keyfile); return; } - do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", NULL); - do_pngs = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoPngs", &error); + do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", &error); if (error) { - do_pngs = FALSE; + do_cropped = TRUE; g_error_free (error); } @@ -436,7 +388,7 @@ monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); g_signal_connect (G_OBJECT (monitor), "changed", - G_CALLBACK (on_file_changed), NULL); + G_CALLBACK (on_file_changed), NULL); g_object_unref (file); Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c 2008-11-13 11:45:30 UTC (rev 16653) @@ -48,13 +48,12 @@ static gchar *supported[] = { "video/mp4", "video/mpeg", NULL }; static gboolean do_cropped = TRUE; -static gboolean do_pngs = FALSE; static gboolean do_vidthumbs = TRUE; static GFileMonitor *monitor = NULL; typedef struct { const gchar *uri; - const gchar *target; + OutType target; guint size; guint mtime; @@ -90,44 +89,8 @@ ...); #endif -static gboolean -save_thumb_file_meta (GdkPixbuf *pixbuf, const gchar *file, guint64 mtime, const gchar *uri, GError **error) -{ - gboolean ret; - if (do_pngs) { - char mtime_str[64]; - - const char *default_keys[] = { - URI_OPTION, - MTIME_OPTION, - SOFTWARE_OPTION, - NULL - }; - - const char *default_values[] = { - uri, - mtime_str, - HILDON_THUMBNAIL_APPLICATION "-" VERSION, - NULL - }; - - g_sprintf(mtime_str, "%lu", mtime); - - ret = gdk_pixbuf_savev (pixbuf, file, "png", - (char **) default_keys, - (char **) default_values, - error); - } else { - ret = gdk_pixbuf_save (pixbuf, file, "jpeg", - error, NULL); - } - - return ret; -} - static gboolean -create_png(const gchar *target, unsigned char *data, guint width, guint height, guint bpp, - const gchar *uri, guint mtime) +create_output (OutType target, unsigned char *data, guint width, guint height, guint bpp, const gchar *uri, guint mtime) { GdkPixbuf *pixbuf = NULL; GError *error = NULL; @@ -140,14 +103,22 @@ width*3, /* Number of bytes between lines (ie stride) */ NULL, NULL); /* Callbacks */ - if(!save_thumb_file_meta(pixbuf, target, mtime, uri, &error)) - { + hildon_thumbnail_outplugins_do_out (gdk_pixbuf_get_pixels (pixbuf), + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + gdk_pixbuf_get_rowstride (pixbuf), + target, + mtime, + uri, + &error); + + if (error) { g_warning("%s\n", error->message); g_error_free(error); g_object_unref(pixbuf); return FALSE; } - + g_object_unref(pixbuf); return TRUE; } @@ -161,12 +132,9 @@ unsigned char *data_photo = (unsigned char *) GST_BUFFER_DATA(buffer); - /* Create a PNG of the data and check the status */ - if(!create_png(thumber->target, data_photo, - thumber->size, thumber->size, - 24, thumber->uri, thumber->mtime)) { - g_error ("Creation of thumbnail failed"); - } + create_output (thumber->target, data_photo, + thumber->size, thumber->size, + 24, thumber->uri, thumber->mtime); g_main_loop_quit (thumber->loop); @@ -208,7 +176,7 @@ VideoThumbnailer *thumber) { gchar *message_str; - GError *error; + GError *error = NULL; GstState old_state, new_state; gint64 duration = -1; gint64 position = -1; @@ -219,16 +187,20 @@ case GST_MESSAGE_ERROR: gst_message_parse_error(message, &error, &message_str); - g_error("GStreamer error: %s\n", message_str); - g_free(error); + g_warning("GStreamer error: %s\n", message_str); + if (error) + g_error_free (error); g_free(message_str); + g_main_loop_quit (thumber->loop); break; case GST_MESSAGE_WARNING: gst_message_parse_warning(message, &error, &message_str); g_warning("GStreamer warning: %s\n", message_str); - g_free(error); + if (error) + g_error_free(error); g_free(message_str); + g_main_loop_quit (thumber->loop); break; case GST_MESSAGE_EOS: @@ -262,7 +234,7 @@ if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) { if (!gst_element_seek_simple (thumber->pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, position)) { - g_error ("Seek failed"); + g_warning ("Seek failed"); } } break; @@ -270,6 +242,7 @@ case GST_MESSAGE_APPLICATION: case GST_MESSAGE_TAG: default: + g_main_loop_quit (thumber->loop); /* unhandled message */ break; } @@ -377,6 +350,8 @@ /* Run */ thumber->loop = g_main_loop_new (NULL, FALSE); gst_element_set_state (thumber->pipeline, GST_STATE_PAUSED); + + // g_timeout_add_seconds (10, g_main_loop_quit, thumber->loop); g_main_loop_run (thumber->loop); cleanup: @@ -439,10 +414,6 @@ while (uris[i] != NULL) { GError *nerror = NULL; - hildon_thumbnail_util_get_thumb_paths (uris[i], &large, &normal, - &cropped, NULL, NULL, NULL, - do_pngs); - /* Create the thumbnailer struct */ thumber = g_slice_new0 (VideoThumbnailer); @@ -450,7 +421,7 @@ thumber->video_fps_n = thumber->video_fps_d = -1; thumber->video_height = thumber->video_width = -1; thumber->uri = uris[i]; - thumber->target = normal; + thumber->target = OUTTYPE_NORMAL; thumber->size = 128; video_thumbnail_create (thumber, &nerror); @@ -458,11 +429,21 @@ if (nerror) goto nerror_handler; - thumber->target = large; + thumber->target = OUTTYPE_LARGE; thumber->size = 256; video_thumbnail_create (thumber, &nerror); + if (nerror) + goto nerror_handler; + + if (do_cropped) { + thumber->target = OUTTYPE_CROPPED; + thumber->size = 124; + + video_thumbnail_create (thumber, &nerror); + } + nerror_handler: g_slice_free (VideoThumbnailer, thumber); @@ -477,10 +458,6 @@ nerror = NULL; } - g_free (large); - g_free (normal); - g_free (cropped); - i++; } @@ -525,16 +502,14 @@ if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) { do_cropped = TRUE; - do_pngs = FALSE; g_key_file_free (keyfile); return; } - do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", NULL); - do_pngs = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoPngs", &error); + do_cropped = g_key_file_get_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", &error); if (error) { - do_pngs = FALSE; + do_cropped = TRUE; g_error_free (error); } Modified: projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c 2008-11-13 11:40:24 UTC (rev 16652) +++ projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c 2008-11-13 11:45:30 UTC (rev 16653) @@ -1010,7 +1010,7 @@ G_TYPE_NONE, 4, G_TYPE_UINT, - G_TYPE_BOXED, + G_TYPE_STRV, G_TYPE_INT, G_TYPE_STRING);
- Previous message: [maemo-commits] r16652 - projects/haf/tags/totem-pl-parser
- Next message: [maemo-commits] r16654 - projects/haf/trunk/hildon-thumbnail/daemon/plugins
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]