[maemo-commits] [maemo-commits] r16703 - in projects/haf/trunk/hildon-thumbnail: . daemon daemon/plugins

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Nov 17 16:28:58 EET 2008
Author: pvanhoof
Date: 2008-11-17 16:28:56 +0200 (Mon, 17 Nov 2008)
New Revision: 16703

Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   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/epeg-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c
Log:
2008-11-17  Philip Van Hoof  <philip at codeminded.be>

	* daemon/hildon-thumbnail-plugin.h
	* daemon/plugins/gdkpixbuf-plugin.c
	* daemon/plugins/gstreamer-video-plugin.c
	* daemon/plugins/epeg-plugin.c
	* daemon/hildon-thumbnail-plugin.c: Performance improvements:
	avoiding rescaling when there's no need to recreate the thumbnail



Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-11-17 13:25:16 UTC (rev 16702)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-11-17 14:28:56 UTC (rev 16703)
@@ -1,3 +1,13 @@
+2008-11-17  Philip Van Hoof  <philip at codeminded.be>
+
+	* daemon/hildon-thumbnail-plugin.h
+	* daemon/plugins/gdkpixbuf-plugin.c
+	* daemon/plugins/gstreamer-video-plugin.c
+	* daemon/plugins/epeg-plugin.c
+	* daemon/hildon-thumbnail-plugin.c: Performance improvements:
+	avoiding rescaling when there's no need to recreate the thumbnail
+
+
 2008-11-17  Marius Vollmer  <marius.vollmer at nokia.com>
 
 	Released 3.0.10

Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c	2008-11-17 13:25:16 UTC (rev 16702)
+++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c	2008-11-17 14:28:56 UTC (rev 16703)
@@ -79,21 +79,15 @@
 
 
 
-typedef gboolean (*NeedsOutFunc) (const guchar *rgb8_pixmap, 
-			 guint width, guint height,
-			 guint rowstride, guint bits_per_sample,
-			 OutType type,
-			 guint64 mtime, 
-			 const gchar *uri);
+typedef gboolean (*NeedsOutFunc) (OutType type,
+			 	  guint64 mtime, 
+			 	  const gchar *uri);
 
 
 gboolean
-hildon_thumbnail_outplugins_needs_out (const guchar *rgb8_pixmap, 
-						   guint width, guint height,
-						   guint rowstride, guint bits_per_sample,
-						   OutType type,
-						   guint64 mtime, 
-						   const gchar *uri)
+hildon_thumbnail_outplugins_needs_out (OutType type,
+				       guint64 mtime, 
+				       const gchar *uri)
 {
 	GList *copy = g_list_copy (outplugs);
 	gboolean retval = FALSE;
@@ -109,7 +103,7 @@
 			IsActiveFunc isac_func;
 			if (g_module_symbol (module, "hildon_thumbnail_outplugin_is_active", (gpointer *) &isac_func)) {
 				if (isac_func ()) {
-					retval = needs_out_func (rgb8_pixmap, width, height, rowstride, bits_per_sample, type, mtime, uri);
+					retval = needs_out_func (type, mtime, uri);
 				} 
 			} 
 		}

Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h	2008-11-17 13:25:16 UTC (rev 16702)
+++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h	2008-11-17 14:28:56 UTC (rev 16703)
@@ -65,10 +65,7 @@
 						   guint64 mtime, 
 						   const gchar *uri, 
 						   GError **error);
-gboolean    hildon_thumbnail_outplugins_needs_out (const guchar *rgb8_pixmap, 
-						   guint width, guint height,
-						   guint rowstride, guint bits_per_sample,
-						   OutType type,
+gboolean    hildon_thumbnail_outplugins_needs_out (OutType type,
 						   guint64 mtime, 
 						   const gchar *uri);
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c	2008-11-17 13:25:16 UTC (rev 16702)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c	2008-11-17 14:28:56 UTC (rev 16703)
@@ -153,13 +153,12 @@
 		gboolean had_err = FALSE;
 		guchar *data;
 		GdkPixbuf *pixbuf_large = NULL, 
-				  *pixbuf_normal, 
-				  *pixbuf_cropped;
+			  *pixbuf_normal, 
+			  *pixbuf_cropped;
 		guint64 mtime;
 		GFileInfo *finfo = NULL;
 		GError *nerror = NULL;
 		guint ow, oh;
-
 		const guchar *rgb8_pixels;
 		guint width; guint height;
 		guint rowstride; 
@@ -183,6 +182,11 @@
 
 		mtime = g_file_info_get_attribute_uint64 (finfo, G_FILE_ATTRIBUTE_TIME_MODIFIED);
 
+		if (!hildon_thumbnail_outplugins_needs_out (OUTTYPE_LARGE, mtime, uri) &&
+		    !hildon_thumbnail_outplugins_needs_out (OUTTYPE_NORMAL, mtime, uri) &&
+		     hildon_thumbnail_outplugins_needs_out (OUTTYPE_CROPPED, mtime, uri))
+			goto nerror_handler;
+
 		im = epeg_file_open (path);
 
 		if (!im) {
@@ -220,97 +224,73 @@
 									  destroy_pixbuf, im);
 		}
 
-		rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_large);
-		width = gdk_pixbuf_get_width (pixbuf_large);
-		height = gdk_pixbuf_get_height (pixbuf_large);
-		rowstride = gdk_pixbuf_get_rowstride (pixbuf_large);
+		if (hildon_thumbnail_outplugins_needs_out (OUTTYPE_LARGE, mtime, uri)) {
 
-		if (hildon_thumbnail_outplugins_needs_out (rgb8_pixels, 
-							   width,
-							   height,
-							   rowstride,
-							   8,
-							   OUTTYPE_LARGE,
-							   mtime, 
-							   uri)) {
+			rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_large);
+			width = gdk_pixbuf_get_width (pixbuf_large);
+			height = gdk_pixbuf_get_height (pixbuf_large);
+			rowstride = gdk_pixbuf_get_rowstride (pixbuf_large);
 
 			hildon_thumbnail_outplugins_do_out (rgb8_pixels, 
 							    width,
 							    height,
-							    rowstride,
-							    8,
+							    rowstride, 8,
 							    OUTTYPE_LARGE,
-							    mtime, 
-							    uri, 
+							    mtime, uri, 
 							    &nerror);
 		}
 
 		if (nerror)
 			goto nerror_handler;
 
-		pixbuf_cropped = crop_resize (pixbuf_large, 124, 124);
+		if (do_cropped && hildon_thumbnail_outplugins_needs_out (OUTTYPE_CROPPED, mtime, uri)) {
 
-		rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_cropped);
-		width = gdk_pixbuf_get_width (pixbuf_cropped);
-		height = gdk_pixbuf_get_height (pixbuf_cropped);
-		rowstride = gdk_pixbuf_get_rowstride (pixbuf_cropped);
+			pixbuf_cropped = crop_resize (pixbuf_large, 124, 124);
 
-		if (hildon_thumbnail_outplugins_needs_out (rgb8_pixels, 
-							   width,
-							   height,
-							   rowstride,
-							   8,
-							   OUTTYPE_CROPPED,
-							   mtime, 
-							   uri)) {
+			rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_cropped);
+			width = gdk_pixbuf_get_width (pixbuf_cropped);
+			height = gdk_pixbuf_get_height (pixbuf_cropped);
+			rowstride = gdk_pixbuf_get_rowstride (pixbuf_cropped);
 
 			hildon_thumbnail_outplugins_do_out (rgb8_pixels, 
 							    width,
 							    height,
-							    rowstride,
-							    8,
+							    rowstride, 8,
 							    OUTTYPE_CROPPED,
-							    mtime, 
-							    uri, 
+							    mtime, uri, 
 							    &nerror);
-		}
 
-		g_object_unref (pixbuf_cropped);
+			g_object_unref (pixbuf_cropped);
 
+		}
+
 		if (nerror)
 			goto nerror_handler;
 
-		pixbuf_normal = gdk_pixbuf_scale_simple (pixbuf_large,
-							 128, 128,
-							 GDK_INTERP_HYPER);
 
-		rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_normal);
-		width = gdk_pixbuf_get_width (pixbuf_normal);
-		height = gdk_pixbuf_get_height (pixbuf_normal);
-		rowstride = gdk_pixbuf_get_rowstride (pixbuf_normal);
+		if (hildon_thumbnail_outplugins_needs_out (OUTTYPE_NORMAL, mtime, uri)) {
 
-		if (hildon_thumbnail_outplugins_needs_out (rgb8_pixels, 
-							   width,
-							   height,
-							   rowstride,
-							   8,
-							   OUTTYPE_NORMAL,
-							   mtime, 
-							   uri)) {
+			pixbuf_normal = gdk_pixbuf_scale_simple (pixbuf_large,
+								 128, 128,
+								 GDK_INTERP_HYPER);
 
-		    hildon_thumbnail_outplugins_do_out (rgb8_pixels, 
-						    width,
-						    height,
-						    rowstride,
-						    8,
-						    OUTTYPE_NORMAL,
-						    mtime, 
-						    uri, 
-						    &nerror);
-		}
+			rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_normal);
+			width = gdk_pixbuf_get_width (pixbuf_normal);
+			height = gdk_pixbuf_get_height (pixbuf_normal);
+			rowstride = gdk_pixbuf_get_rowstride (pixbuf_normal);
 
-		g_object_unref (pixbuf_normal);
+			hildon_thumbnail_outplugins_do_out (rgb8_pixels, 
+							    width,
+							    height,
+							    rowstride, 8,
+							    OUTTYPE_NORMAL,
+							    mtime, uri, 
+							    &nerror);
 
+			g_object_unref (pixbuf_normal);
+
+		}
+
 		if (nerror)
 			goto nerror_handler;
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2008-11-17 13:25:16 UTC (rev 16702)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2008-11-17 14:28:56 UTC (rev 16703)
@@ -175,12 +175,10 @@
 		GdkPixbuf *pixbuf_normal;
 		GdkPixbuf *pixbuf, *pixbuf_cropped;
 		guint64 mtime;
-
 		const guchar *rgb8_pixels;
 		guint width; guint height;
 		guint rowstride; 
 
-
 		file = g_file_new_for_uri (uri);
 
 		info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED,
@@ -192,33 +190,31 @@
 
 		mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
 
+		if (!hildon_thumbnail_outplugins_needs_out (OUTTYPE_LARGE, mtime, uri) &&
+		    !hildon_thumbnail_outplugins_needs_out (OUTTYPE_NORMAL, mtime, uri) &&
+		     hildon_thumbnail_outplugins_needs_out (OUTTYPE_CROPPED, mtime, uri))
+			goto nerror_handler;
+
 		stream = g_file_read (file, NULL, &nerror);
 
 		if (nerror)
 			goto nerror_handler;
 
-		pixbuf_large = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (stream),
-								    256, 256,
-								    TRUE,
-								    NULL,
-								    &nerror);
+		if (hildon_thumbnail_outplugins_needs_out (OUTTYPE_LARGE, mtime, uri)) {
 
-		if (nerror)
-			goto nerror_handler;
+			pixbuf_large = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (stream),
+									    256, 256,
+									    TRUE,
+									    NULL,
+									    &nerror);
 
-		rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_large);
-		width = gdk_pixbuf_get_width (pixbuf_large);
-		height = gdk_pixbuf_get_height (pixbuf_large);
-		rowstride = gdk_pixbuf_get_rowstride (pixbuf_large);
+			if (nerror)
+				goto nerror_handler;
 
-		if (hildon_thumbnail_outplugins_needs_out (rgb8_pixels, 
-							   width,
-							   height,
-							   rowstride,
-							   8,
-							   OUTTYPE_LARGE,
-							   mtime, 
-							   uri)) {
+			rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_large);
+			width = gdk_pixbuf_get_width (pixbuf_large);
+			height = gdk_pixbuf_get_height (pixbuf_large);
+			rowstride = gdk_pixbuf_get_rowstride (pixbuf_large);
 
 			hildon_thumbnail_outplugins_do_out (rgb8_pixels, 
 							    width,
@@ -229,87 +225,76 @@
 							    mtime, 
 							    uri, 
 							    &nerror);
-		}
 
-		g_object_unref (pixbuf_large);
+			g_object_unref (pixbuf_large);
 
-		if (nerror)
-			goto nerror_handler;
+			if (nerror)
+				goto nerror_handler;
 
-		g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, &nerror);
+			g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, &nerror);
 
-		if (nerror)
-			goto nerror_handler;
+			if (nerror)
+				goto nerror_handler;
 
-		pixbuf_normal = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (stream),
-								     128, 128,
-								     TRUE,
-								     NULL,
-								     &nerror);
+		}
 
-		if (nerror)
-			goto nerror_handler;
 
-		rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_normal);
-		width = gdk_pixbuf_get_width (pixbuf_normal);
-		height = gdk_pixbuf_get_height (pixbuf_normal);
-		rowstride = gdk_pixbuf_get_rowstride (pixbuf_normal);
+		if (hildon_thumbnail_outplugins_needs_out (OUTTYPE_NORMAL, mtime, uri)) {
 
-		if (hildon_thumbnail_outplugins_needs_out (rgb8_pixels, 
-							   width,
-							   height,
-							   rowstride,
-							   8,
-							   OUTTYPE_NORMAL,
-							   mtime, 
-							   uri)) {
+			pixbuf_normal = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (stream),
+									     128, 128,
+									     TRUE,
+									     NULL,
+									     &nerror);
 
-		    hildon_thumbnail_outplugins_do_out (rgb8_pixels, 
-						    width,
-						    height,
-						    rowstride,
-						    8,
-						    OUTTYPE_NORMAL,
-						    mtime, 
-						    uri, 
-						    &nerror);
-		}
+			if (nerror)
+				goto nerror_handler;
 
-		g_object_unref (pixbuf_normal);
+			rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_normal);
+			width = gdk_pixbuf_get_width (pixbuf_normal);
+			height = gdk_pixbuf_get_height (pixbuf_normal);
+			rowstride = gdk_pixbuf_get_rowstride (pixbuf_normal);
 
-		if (nerror)
-			goto nerror_handler;
+			hildon_thumbnail_outplugins_do_out (rgb8_pixels, 
+							    width,
+							    height,
+							    rowstride,
+							    8,
+							    OUTTYPE_NORMAL,
+							    mtime, 
+							    uri, 
+							    &nerror);
 
-		g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, &nerror);
+			g_object_unref (pixbuf_normal);
 
-		if (nerror)
-			goto nerror_handler;
+			if (nerror)
+				goto nerror_handler;
 
-		pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream),
-						     NULL,
-						     &nerror);
+			g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, &nerror);
 
-		if (nerror)
-			goto nerror_handler;
+			if (nerror)
+				goto nerror_handler;
 
-		pixbuf_cropped = crop_resize (pixbuf, 124, 124);
+		}
 
-		g_object_unref (pixbuf);
+		if (do_cropped && hildon_thumbnail_outplugins_needs_out (OUTTYPE_CROPPED, mtime, uri)) {
 
-		rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_cropped);
-		width = gdk_pixbuf_get_width (pixbuf_cropped);
-		height = gdk_pixbuf_get_height (pixbuf_cropped);
-		rowstride = gdk_pixbuf_get_rowstride (pixbuf_cropped);
+			pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream),
+							     NULL,
+							     &nerror);
 
-		if (hildon_thumbnail_outplugins_needs_out (rgb8_pixels, 
-							   width,
-							   height,
-							   rowstride,
-							   8,
-							   OUTTYPE_CROPPED,
-							   mtime, 
-							   uri)) {
+			if (nerror)
+				goto nerror_handler;
 
+			pixbuf_cropped = crop_resize (pixbuf, 124, 124);
+
+			g_object_unref (pixbuf);
+
+			rgb8_pixels = gdk_pixbuf_get_pixels (pixbuf_cropped);
+			width = gdk_pixbuf_get_width (pixbuf_cropped);
+			height = gdk_pixbuf_get_height (pixbuf_cropped);
+			rowstride = gdk_pixbuf_get_rowstride (pixbuf_cropped);
+				
 			hildon_thumbnail_outplugins_do_out (rgb8_pixels, 
 							    width,
 							    height,
@@ -319,11 +304,14 @@
 							    mtime, 
 							    uri, 
 							    &nerror);
-		}
 
+			g_object_unref (pixbuf_cropped);
 
-		g_object_unref (pixbuf_cropped);
+			if (nerror)
+				goto nerror_handler;
 
+		}
+
 		nerror_handler:
 
 		if (stream)

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-17 13:25:16 UTC (rev 16702)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-11-17 14:28:56 UTC (rev 16703)
@@ -50,7 +50,7 @@
 	OutType         target;
 	guint           size;
 
-	guint           mtime;
+	guint64         mtime;
 
 	GCond          *condition;
 	gboolean        had_callback, set_state;
@@ -90,14 +90,7 @@
 {
 	GError *error = NULL;
 
-	if (hildon_thumbnail_outplugins_needs_out (data, 
-						   width,
-						   height,
-						   width*3,
-						   bpp/3,
-						   target,
-						   mtime, 
-						   uri)) {
+	if (hildon_thumbnail_outplugins_needs_out (target, mtime, uri)) {
 
 		hildon_thumbnail_outplugins_do_out (data, 
 						    width,
@@ -461,37 +454,68 @@
 
 	while (uris[i] != NULL) {
 		GError *nerror = NULL;
+		GFile *file = NULL;
+		GFileInfo *finfo = NULL;
+		guint64 mtime;
 
+		file = g_file_new_for_uri (uris[i]);
+
+		finfo = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED,
+					   G_FILE_QUERY_INFO_NONE,
+					   NULL, &nerror);
+
+		if (nerror)
+			goto nerror_handler;
+
+		mtime = g_file_info_get_attribute_uint64 (finfo, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+
+		if (!hildon_thumbnail_outplugins_needs_out (OUTTYPE_LARGE, mtime, uris[i]) &&
+		    !hildon_thumbnail_outplugins_needs_out (OUTTYPE_NORMAL, mtime, uris[i]) &&
+		     hildon_thumbnail_outplugins_needs_out (OUTTYPE_CROPPED, mtime, uris[i]))
+			goto nerror_handler;
+
 		/* Create the thumbnailer struct */
 		thumber = g_slice_new0 (VideoThumbnailer);
 
 		thumber->pipe_lock = g_mutex_new ();
 
+		thumber->mtime        = mtime;
 		thumber->has_audio    = thumber->has_video = FALSE;
 		thumber->video_fps_n  = thumber->video_fps_d = -1;
 		thumber->video_height = thumber->video_width = -1;
 		thumber->uri          = uris[i];
-		thumber->target       = OUTTYPE_NORMAL;
-		thumber->size         = 128;
+		
 
-		video_thumbnail_create (thumber, &nerror);
+		if (hildon_thumbnail_outplugins_needs_out (OUTTYPE_NORMAL, mtime, uris[i])) {
+			thumber->target       = OUTTYPE_NORMAL;
+			thumber->size         = 128;
 
-		if (nerror)
-			goto nerror_handler;
+			video_thumbnail_create (thumber, &nerror);
 
-		thumber->target       = OUTTYPE_LARGE;
-		thumber->size         = 256;
+			if (nerror)
+				goto nerror_handler;
+		}
 
-		video_thumbnail_create (thumber, &nerror);
+		if (hildon_thumbnail_outplugins_needs_out (OUTTYPE_LARGE, mtime, uris[i])) {
 
-		if (nerror)
-			goto nerror_handler;
+			thumber->target       = OUTTYPE_LARGE;
+			thumber->size         = 256;
 
-		if (do_cropped) {
+			video_thumbnail_create (thumber, &nerror);
+
+			if (nerror)
+				goto nerror_handler;
+		}
+
+		if (do_cropped && hildon_thumbnail_outplugins_needs_out (OUTTYPE_CROPPED, mtime, uris[i])) {
 			thumber->target       = OUTTYPE_CROPPED;
 			thumber->size         = 124;
 
 			video_thumbnail_create (thumber, &nerror);
+
+			if (nerror)
+				goto nerror_handler;
+
 		}
 
 		nerror_handler:
@@ -500,6 +524,12 @@
 
 		g_slice_free (VideoThumbnailer, thumber);
 
+		if (finfo)
+			g_object_unref (finfo);
+
+		if (file)
+			g_object_unref (file);
+
 		if (nerror) {
 			if (!errors)
 				errors = g_string_new ("");


More information about the maemo-commits mailing list