Updating branch refs/heads/master to 2621ee8d1db623ef28f8b4aabd7fb246f9e8991e (commit) from 50b035316092be7c22f652bc65fb8c133453b7d1 (commit)
commit 2621ee8d1db623ef28f8b4aabd7fb246f9e8991e Author: Lionel Le Folgoc <mrpo...@ubuntu.com> Date: Sat Mar 6 00:21:47 2010 +0100 Add a video thumbnailer (using libffmpegthumbnailer). Signed-off-by: Jannis Pohlmann <jan...@xfce.org> acinclude.m4 | 23 ++ configure.ac | 23 +- plugins/Makefile.am | 1 + .../Makefile.am | 28 +- .../ffmpeg-thumbnailer-plugin.c} | 15 +- .../ffmpeg-thumbnailer-provider.c} | 63 +++-- .../ffmpeg-thumbnailer-provider.h | 44 +++ plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c | 307 ++++++++++++++++++++ plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.h | 44 +++ po/POTFILES.in | 3 + 10 files changed, 495 insertions(+), 56 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 568b4d7..ca93400 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -121,6 +121,29 @@ AC_MSG_RESULT([$ac_tumbler_jpeg_thumbnailer]) ]) +dnl TUMBLER_FFMPEG_THUMBNAILER() +dnl +dnl Check whether to build and install the ffmpeg video thumbnailer plugin. +dnl +AC_DEFUN([TUMBLER_FFMPEG_THUMBNAILER], +[ +AC_ARG_ENABLE([ffmpeg-thumbnailer], [AC_HELP_STRING([--disable-ffmpeg-thumbnailer], [Don't build the ffmpeg video thumbnailer plugin])], + [ac_tumbler_ffmpeg_thumbnailer=$enableval], [ac_tumbler_ffmpeg_thumbnailer=yes]) +if test x"$ac_tumbler_ffmpeg_thumbnailer" = x"yes"; then + dnl Check for gdk-pixbuf + PKG_CHECK_MODULES([GDK_PIXBUF], [gdk-pixbuf-2.0 >= 2.14], + [ + dnl Check for libffmpegthumbnailer + PKG_CHECK_MODULES([FFMPEGTHUMBNAILER], [libffmpegthumbnailer >= 2.0.0], [], [ac_tumbler_ffmpeg_thumbnailer=no]) + ], [ac_tumbler_ffmpeg_thumbnailer=no]) +fi + +AC_MSG_CHECKING([whether to build the ffmpeg video thumbnailer plugin]) +AM_CONDITIONAL([TUMBLER_FFMPEG_THUMBNAILER], [test x"$ac_tumbler_ffmpeg_thumbnailer" = x"yes"]) +AC_MSG_RESULT([$ac_tumbler_ffmpeg_thumbnailer]) +]) + + dnl TUMBLER_XDG_CACHE() dnl diff --git a/configure.ac b/configure.ac index 5db2e4e..599ccc8 100644 --- a/configure.ac +++ b/configure.ac @@ -153,6 +153,7 @@ dnl ************************* TUMBLER_FONT_THUMBNAILER() TUMBLER_JPEG_THUMBNAILER() TUMBLER_PIXBUF_THUMBNAILER() +TUMBLER_FFMPEG_THUMBNAILER() TUMBLER_XDG_CACHE() dnl *********************************** @@ -181,6 +182,7 @@ plugins/Makefile plugins/font-thumbnailer/Makefile plugins/jpeg-thumbnailer/Makefile plugins/pixbuf-thumbnailer/Makefile +plugins/ffmpeg-thumbnailer/Makefile plugins/xdg-cache/Makefile po/Makefile.in tumbler/Makefile @@ -200,23 +202,28 @@ echo echo "Plugins:" echo if test x"$ac_tumbler_pixbuf_thumbnailer" = x"yes"; then -echo " * GdkPixbuf thumbnailer plugin: yes" +echo " * GdkPixbuf thumbnailer plugin: yes" else -echo " * GdkPixbuf thumbnailer plugin: no" +echo " * GdkPixbuf thumbnailer plugin: no" fi if test x"$ac_tumbler_font_thumbnailer" = x"yes"; then -echo " * FreeType font thumbnailer plugin: yes" +echo " * FreeType font thumbnailer plugin: yes" else -echo " * FreeType font thumbnailer plugin: no" +echo " * FreeType font thumbnailer plugin: no" fi if test x"$ac_tumbler_jpeg_thumbnailer" = x"yes"; then -echo " * JPEG thumbnailer plugin with EXIF support: yes" +echo " * JPEG thumbnailer plugin with EXIF support: yes" else -echo " * JPEG thumbnailer plugin with EXIF support: no" +echo " * JPEG thumbnailer plugin with EXIF support: no" +fi +if test x"$ac_tumbler_ffmpeg_thumbnailer" = x"yes"; then +echo " * Video thumbnailer plugin using ffmpegthumbnailer: yes" +else +echo " * Video thumbnailer plugin using ffmpegthumbnailer: no" fi if test x"$ac_tumbler_xdg_cache" = x"yes"; then -echo " * Freedesktop.org cache plugin: yes" +echo " * Freedesktop.org cache plugin: yes" else -echo " * Freedesktop.org cache plugin: no" +echo " * Freedesktop.org cache plugin: no" fi echo diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 983884b..1320b14 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -21,4 +21,5 @@ SUBDIRS = \ font-thumbnailer \ jpeg-thumbnailer \ pixbuf-thumbnailer \ + ffmpeg-thumbnailer \ xdg-cache diff --git a/plugins/jpeg-thumbnailer/Makefile.am b/plugins/ffmpeg-thumbnailer/Makefile.am similarity index 72% copy from plugins/jpeg-thumbnailer/Makefile.am copy to plugins/ffmpeg-thumbnailer/Makefile.am index d4d88a5..1aae717 100644 --- a/plugins/jpeg-thumbnailer/Makefile.am +++ b/plugins/ffmpeg-thumbnailer/Makefile.am @@ -17,42 +17,42 @@ # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -if TUMBLER_JPEG_THUMBNAILER +if TUMBLER_FFMPEG_THUMBNAILER tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins tumbler_plugin_LTLIBRARIES = \ - tumbler-jpeg-thumbnailer.la + tumbler-ffmpeg-thumbnailer.la -tumbler_jpeg_thumbnailer_la_SOURCES = \ - jpeg-thumbnailer-plugin.c \ - jpeg-thumbnailer-provider.c \ - jpeg-thumbnailer-provider.h \ - jpeg-thumbnailer.c \ - jpeg-thumbnailer.h +tumbler_ffmpeg_thumbnailer_la_SOURCES = \ + ffmpeg-thumbnailer-plugin.c \ + ffmpeg-thumbnailer-provider.c \ + ffmpeg-thumbnailer-provider.h \ + ffmpeg-thumbnailer.c \ + ffmpeg-thumbnailer.h -tumbler_jpeg_thumbnailer_la_CFLAGS = \ +tumbler_ffmpeg_thumbnailer_la_CFLAGS = \ -I$(top_builddir) \ -I$(top_builddir)/plugins \ -I$(top_srcdir) \ -I$(top_srcdir)/plugins \ - -DG_LOG_DOMAIN=\"tumbler-jpeg-thumbnailer\" \ + -DG_LOG_DOMAIN=\"tumbler-ffmpeg-thumbnailer\" \ -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ $(GDK_PIXBUF_CFLAGS) \ $(GIO_CFLAGS) \ $(GLIB_CFLAGS) \ - $(LIBJPEG_CFLAGS) \ + $(FFMPEGTHUMBNAILER_CFLAGS) \ $(PLATFORM_CPPFLAGS) -tumbler_jpeg_thumbnailer_la_LDFLAGS = \ +tumbler_ffmpeg_thumbnailer_la_LDFLAGS = \ -avoid-version \ -export-dynamic \ -module \ $(PLATFORM_LDFLAGS) -tumbler_jpeg_thumbnailer_la_LIBADD = \ +tumbler_ffmpeg_thumbnailer_la_LIBADD = \ $(GDK_PIXBUF_LIBS) \ $(GIO_LIBS) \ $(GLIB_LIBS) \ - $(LIBJPEG_LIBS) + $(FFMPEGTHUMBNAILER_LIBS) endif diff --git a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-plugin.c b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-plugin.c similarity index 81% copy from plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-plugin.c copy to plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-plugin.c index 0cf1fc3..93fec59 100644 --- a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-plugin.c +++ b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-plugin.c @@ -1,6 +1,7 @@ /* vi:set et ai sw=2 sts=2 ts=2: */ /*- * Copyright (c) 2009 Jannis Pohlmann <jan...@xfce.org> + * Copyright (c) 2010 Lionel Le Folgoc <mrpo...@ubuntu.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,8 +29,8 @@ #include <tumbler/tumbler.h> -#include <pixbuf-thumbnailer/pixbuf-thumbnailer-provider.h> -#include <pixbuf-thumbnailer/pixbuf-thumbnailer.h> +#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.h> +#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer.h> @@ -59,15 +60,15 @@ tumbler_plugin_initialize (TumblerProviderPlugin *plugin) } #ifdef DEBUG - g_message (_("Initializing the Tumbler Pixbuf Thumbnailer plugin")); + g_message (_("Initializing the Tumbler ffmpeg video thumbnailer plugin")); #endif /* register the types provided by this plugin */ - pixbuf_thumbnailer_register (plugin); - pixbuf_thumbnailer_provider_register (plugin); + ffmpeg_thumbnailer_register (plugin); + ffmpeg_thumbnailer_provider_register (plugin); /* set up the plugin provider type list */ - type_list[0] = TYPE_PIXBUF_THUMBNAILER_PROVIDER; + type_list[0] = TYPE_FFMPEG_THUMBNAILER_PROVIDER; } @@ -76,7 +77,7 @@ void tumbler_plugin_shutdown (void) { #ifdef DEBUG - g_message (_("Shutting down the Tumbler Pixbuf Thumbnailer plugin")); + g_message (_("Shutting down the Tumbler ffmpeg video thumbnailer plugin")); #endif } diff --git a/plugins/font-thumbnailer/font-thumbnailer-provider.c b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c similarity index 53% copy from plugins/font-thumbnailer/font-thumbnailer-provider.c copy to plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c index 65158a5..09ff768 100644 --- a/plugins/font-thumbnailer/font-thumbnailer-provider.c +++ b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c @@ -1,6 +1,7 @@ /* vi:set et ai sw=2 sts=2 ts=2: */ /*- * Copyright (c) 2009 Jannis Pohlmann <jan...@xfce.org> + * Copyright (c) 2010 Lionel Le Folgoc <mrpo...@ubuntu.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,47 +30,47 @@ #include <tumbler/tumbler.h> -#include <font-thumbnailer/font-thumbnailer-provider.h> -#include <font-thumbnailer/font-thumbnailer.h> +#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.h> +#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer.h> -static void font_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface); -static GList *font_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider); +static void ffmpeg_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface); +static GList *ffmpeg_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider); -struct _FontThumbnailerProviderClass +struct _FfmpegThumbnailerProviderClass { GObjectClass __parent__; }; -struct _FontThumbnailerProvider +struct _FfmpegThumbnailerProvider { GObject __parent__; }; -G_DEFINE_DYNAMIC_TYPE_EXTENDED (FontThumbnailerProvider, - font_thumbnailer_provider, +G_DEFINE_DYNAMIC_TYPE_EXTENDED (FfmpegThumbnailerProvider, + ffmpeg_thumbnailer_provider, G_TYPE_OBJECT, 0, TUMBLER_ADD_INTERFACE (TUMBLER_TYPE_THUMBNAILER_PROVIDER, - font_thumbnailer_provider_thumbnailer_provider_init)); + ffmpeg_thumbnailer_provider_thumbnailer_provider_init)); void -font_thumbnailer_provider_register (TumblerProviderPlugin *plugin) +ffmpeg_thumbnailer_provider_register (TumblerProviderPlugin *plugin) { - font_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin)); + ffmpeg_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin)); } static void -font_thumbnailer_provider_class_init (FontThumbnailerProviderClass *klass) +ffmpeg_thumbnailer_provider_class_init (FfmpegThumbnailerProviderClass *klass) { GObjectClass *gobject_class; @@ -79,39 +80,47 @@ font_thumbnailer_provider_class_init (FontThumbnailerProviderClass *klass) static void -font_thumbnailer_provider_class_finalize (FontThumbnailerProviderClass *klass) +ffmpeg_thumbnailer_provider_class_finalize (FfmpegThumbnailerProviderClass *klass) { } static void -font_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface) +ffmpeg_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface) { - iface->get_thumbnailers = font_thumbnailer_provider_get_thumbnailers; + iface->get_thumbnailers = ffmpeg_thumbnailer_provider_get_thumbnailers; } static void -font_thumbnailer_provider_init (FontThumbnailerProvider *provider) +ffmpeg_thumbnailer_provider_init (FfmpegThumbnailerProvider *provider) { } static GList * -font_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider) +ffmpeg_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider) { - static const gchar *mime_types[] = - { - "application/x-font-otf", - "application/x-font-pcf", - "application/x-font-ttf", - "application/x-font-type1", - NULL, + static const gchar *mime_types[] = + { + "video/jpeg", + "video/mp4", + "video/mpeg", + "video/quicktime", + "video/x-ms-asf", + "video/x-ms-wm", + "video/x-ms-wmv", + "video/x-msvideo", + "video/x-flv", + "application/x-flash-video", + "video/3gpp", + "video/x-matroska", + NULL }; - FontThumbnailer *thumbnailer; + FfmpegThumbnailer *thumbnailer; GList *thumbnailers = NULL; GStrv uri_schemes; @@ -119,8 +128,8 @@ font_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider uri_schemes = tumbler_util_get_supported_uri_schemes (); /* create the pixbuf thumbnailer */ - thumbnailer = g_object_new (TYPE_FONT_THUMBNAILER, - "uri-schemes", uri_schemes, "mime-types", mime_types, + thumbnailer = g_object_new (TYPE_FFMPEG_THUMBNAILER, + "uri-schemes", uri_schemes, "mime-types", mime_types, NULL); /* add the thumbnailer to the list */ diff --git a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.h b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.h new file mode 100644 index 0000000..699e6ba --- /dev/null +++ b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.h @@ -0,0 +1,44 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jan...@xfce.org> + * Copyright (c) 2010 Lionel Le Folgoc <mrpo...@ubuntu.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __FFMPEG_THUMBNAILER_PROVIDER_H__ +#define __FFMPEG_THUMBNAILER_PROVIDER_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS; + +#define TYPE_FFMPEG_THUMBNAILER_PROVIDER (ffmpeg_thumbnailer_provider_get_type ()) +#define FFMPEG_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FFMPEG_THUMBNAILER_PROVIDER, FfmpegThumbnailerProvider)) +#define FFMPEG_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FFMPEG_THUMBNAILER_PROVIDER, FfmpegThumbnailerProviderClass)) +#define IS_FFMPEG_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FFMPEG_THUMBNAILER_PROVIDER)) +#define IS_FFMPEG_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FFMPEG_THUMBNAILER_PROVIDER) +#define FFMPEG_THUMBNAILER_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FFMPEG_THUMBNAILER_PROVIDER, FfmpegThumbnailerProviderClass)) + +typedef struct _FfmpegThumbnailerProviderClass FfmpegThumbnailerProviderClass; +typedef struct _FfmpegThumbnailerProvider FfmpegThumbnailerProvider; + +GType ffmpeg_thumbnailer_provider_get_type (void) G_GNUC_CONST; +void ffmpeg_thumbnailer_provider_register (TumblerProviderPlugin *plugin); + +G_END_DECLS; + +#endif /* !__FFMPEG_THUMBNAILER_PROVIDER_H__ */ diff --git a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c new file mode 100644 index 0000000..04cbb9d --- /dev/null +++ b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c @@ -0,0 +1,307 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jan...@xfce.org> + * Copyright (c) 2010 Lionel Le Folgoc <mrpo...@ubuntu.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <math.h> + +#include <glib.h> +#include <glib/gi18n.h> +#include <glib-object.h> + +#include <gdk-pixbuf/gdk-pixbuf.h> + +#include <libffmpegthumbnailer/videothumbnailerc.h> + +#include <tumbler/tumbler.h> + +#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer.h> + + +static void ffmpeg_thumbnailer_finalize (GObject *object); +static void ffmpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info); + + + +struct _FfmpegThumbnailerClass +{ + TumblerAbstractThumbnailerClass __parent__; +}; + +struct _FfmpegThumbnailer +{ + TumblerAbstractThumbnailer __parent__; + + video_thumbnailer *video; +}; + + + +G_DEFINE_DYNAMIC_TYPE (FfmpegThumbnailer, + ffmpeg_thumbnailer, + TUMBLER_TYPE_ABSTRACT_THUMBNAILER); + + + +void +ffmpeg_thumbnailer_register (TumblerProviderPlugin *plugin) +{ + ffmpeg_thumbnailer_register_type (G_TYPE_MODULE (plugin)); +} + + + +static void +ffmpeg_thumbnailer_class_init (FfmpegThumbnailerClass *klass) +{ + TumblerAbstractThumbnailerClass *abstractthumbnailer_class; + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = ffmpeg_thumbnailer_finalize; + + abstractthumbnailer_class = TUMBLER_ABSTRACT_THUMBNAILER_CLASS (klass); + abstractthumbnailer_class->create = ffmpeg_thumbnailer_create; +} + + + +static void +ffmpeg_thumbnailer_class_finalize (FfmpegThumbnailerClass *klass) +{ +} + + + +static void +ffmpeg_thumbnailer_init (FfmpegThumbnailer *thumbnailer) +{ + /* initialize libffmpegthumbnailer with default parameters */ + thumbnailer->video = video_thumbnailer_create (); + thumbnailer->video->seek_percentage = 15; + thumbnailer->video->overlay_film_strip = 1; + thumbnailer->video->thumbnail_image_type = Png; +} + + + +static void +ffmpeg_thumbnailer_finalize (GObject *object) +{ + FfmpegThumbnailer *thumbnailer = FFMPEG_THUMBNAILER (object); + + /* release the libffmpegthumbnailer video object */ + video_thumbnailer_destroy (thumbnailer->video); + + (*G_OBJECT_CLASS (ffmpeg_thumbnailer_parent_class)->finalize) (object); +} + + + +static GdkPixbuf * +generate_pixbuf (GdkPixbuf *source, + gint dest_width, + gint dest_height) +{ + gdouble hratio; + gdouble wratio; + gint source_width; + gint source_height; + + /* determine the source pixbuf dimensions */ + source_width = gdk_pixbuf_get_width (source); + source_height = gdk_pixbuf_get_height (source); + + /* return the same pixbuf if no scaling is required */ + if (source_width <= dest_width && source_height <= dest_height) + return g_object_ref (source); + + /* determine which axis needs to be scaled down more */ + wratio = (gdouble) source_width / (gdouble) dest_width; + hratio = (gdouble) source_height / (gdouble) dest_height; + + /* adjust the other axis */ + if (hratio > wratio) + dest_width = rint (source_width / hratio); + else + dest_height = rint (source_height / wratio); + + /* scale the pixbuf down to the desired size */ + return gdk_pixbuf_scale_simple (source, MAX (dest_width, 1), MAX (dest_height, 1), + GDK_INTERP_BILINEAR); +} + + + +static void +ffmpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info) +{ + image_data *v_data; + GInputStream *v_stream; + GdkPixbuf *v_pixbuf; + FfmpegThumbnailer *ffmpeg_thumbnailer = FFMPEG_THUMBNAILER (thumbnailer); + TumblerThumbnailFlavor *flavor; + TumblerThumbnail *thumbnail; + TumblerImageData data; + GdkPixbuf *pixbuf; + GFile *file; + GError *error = NULL; + gint dest_width; + gint dest_height; + gchar *path; + const gchar *uri; + + g_return_if_fail (IS_FFMPEG_THUMBNAILER (thumbnailer)); + g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + g_return_if_fail (TUMBLER_IS_FILE_INFO (info)); + + /* do nothing if cancelled */ + if (g_cancellable_is_cancelled (cancellable)) + return; + + /* fetch required info */ + thumbnail = tumbler_file_info_get_thumbnail (info); + g_assert (thumbnail != NULL); + flavor = tumbler_thumbnail_get_flavor (thumbnail); + tumbler_thumbnail_flavor_get_size (flavor, &dest_width, &dest_height); + g_object_unref (flavor); + + /* prepare the video thumbnailer */ + ffmpeg_thumbnailer->video->thumbnail_size = MAX (dest_width, dest_height); + v_data = video_thumbnailer_create_image_data (); + + uri = tumbler_file_info_get_uri (info); + + /* try to open the source file for reading */ + file = g_file_new_for_uri (uri); + + if (g_file_is_native (file)) + { + path = g_file_get_path (file); + } + else + { + /* there was an error, emit error signal */ + g_set_error (&error, TUMBLER_ERROR, TUMBLER_ERROR_INVALID_FORMAT, + _("Thumbnail could not be inferred from file contents")); + g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); + g_error_free (error); + + /* clean up */ + g_object_unref (file); + g_object_unref (thumbnail); + video_thumbnailer_destroy_image_data (v_data); + return; + } + g_object_unref (file); + + /* try to generate a thumbnail */ + if (video_thumbnailer_generate_thumbnail_to_buffer (ffmpeg_thumbnailer->video, path, v_data) != 0) + { + /* there was an error, emit error signal */ + g_set_error (&error, TUMBLER_ERROR, TUMBLER_ERROR_INVALID_FORMAT, + _("Thumbnail could not be inferred from file contents")); + g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); + g_error_free (error); + + /* clean up */ + g_free (path); + g_object_unref (thumbnail); + video_thumbnailer_destroy_image_data (v_data); + return; + } + g_free (path); + + v_stream = g_memory_input_stream_new_from_data (v_data->image_data_ptr, + v_data->image_data_size, NULL); + + if (v_stream == NULL) + { + /* there was an error, emit error signal */ + g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); + g_error_free (error); + + /* clean up */ + g_object_unref (thumbnail); + video_thumbnailer_destroy_image_data (v_data); + return; + } + + v_pixbuf = gdk_pixbuf_new_from_stream (v_stream, cancellable, &error); + + g_object_unref (v_stream); + video_thumbnailer_destroy_image_data (v_data); + + if (v_pixbuf == NULL) + { + /* emit an error signal */ + g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); + g_error_free (error); + + /* clean up */ + g_object_unref (thumbnail); + + return; + } + + /* generate a valid thumbnail */ + pixbuf = generate_pixbuf (v_pixbuf, dest_width, dest_height); + + g_assert (pixbuf != NULL); + + /* compose the image data */ + data.data = gdk_pixbuf_get_pixels (pixbuf); + data.has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); + data.bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf); + data.width = gdk_pixbuf_get_width (pixbuf); + data.height = gdk_pixbuf_get_height (pixbuf); + data.rowstride = gdk_pixbuf_get_rowstride (pixbuf); + data.colorspace = (TumblerColorspace) gdk_pixbuf_get_colorspace (pixbuf); + + /* save the thumbnail */ + tumbler_thumbnail_save_image_data (thumbnail, &data, + tumbler_file_info_get_mtime (info), + NULL, &error); + + /* check if there was an error */ + if (error != NULL) + { + /* emit an error signal */ + g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); + g_error_free (error); + } + else + { + /* otherwise, the thumbnail is now ready */ + g_signal_emit_by_name (thumbnailer, "ready", uri); + } + + /* clean up */ + g_object_unref (thumbnail); + g_object_unref (pixbuf); + g_object_unref (v_pixbuf); +} diff --git a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.h b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.h new file mode 100644 index 0000000..62de709 --- /dev/null +++ b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.h @@ -0,0 +1,44 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jan...@xfce.org> + * Copyright (c) 2010 Lionel Le Folgoc <mrpo...@ubuntu.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __FFMPEG_THUMBNAILER_H__ +#define __FFMPEG_THUMBNAILER_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS; + +#define TYPE_FFMPEG_THUMBNAILER (ffmpeg_thumbnailer_get_type ()) +#define FFMPEG_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FFMPEG_THUMBNAILER, FfmpegThumbnailer)) +#define FFMPEG_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FFMPEG_THUMBNAILER, FfmpegThumbnailerClass)) +#define IS_FFMPEG_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FFMPEG_THUMBNAILER)) +#define IS_FFMPEG_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FFMPEG_THUMBNAILER) +#define FFMPEG_THUMBNAILER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FFMPEG_THUMBNAILER, FfmpegThumbnailerClass)) + +typedef struct _FfmpegThumbnailerClass FfmpegThumbnailerClass; +typedef struct _FfmpegThumbnailer FfmpegThumbnailer; + +GType ffmpeg_thumbnailer_get_type (void) G_GNUC_CONST; +void ffmpeg_thumbnailer_register (TumblerProviderPlugin *plugin); + +G_END_DECLS; + +#endif /* !__FFMPEG_THUMBNAILER_H__ */ diff --git a/po/POTFILES.in b/po/POTFILES.in index c68c85b..58e6832 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -27,6 +27,9 @@ plugins/font-thumbnailer/font-thumbnailer-provider.c plugins/jpeg-thumbnailer/jpeg-thumbnailer.c plugins/jpeg-thumbnailer/jpeg-thumbnailer-plugin.c plugins/jpeg-thumbnailer/jpeg-thumbnailer-provider.c +plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c +plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-plugin.c +plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c plugins/xdg-cache/xdg-cache-thumbnail.c plugins/xdg-cache/xdg-cache-plugin.c plugins/xdg-cache/xdg-cache-cache.c _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits