[tracker/tracker-0.6] Optimization for embedded album-art extraction



commit 5cf0071817c711c0564321b683f88471ac9aa077
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed May 20 13:03:58 2009 +0200

    Optimization for embedded album-art extraction
---
 src/tracker-extract/tracker-extract-albumart.c  |   50 +++++++++++++----------
 src/tracker-extract/tracker-extract-albumart.h  |    1 +
 src/tracker-extract/tracker-extract-gstreamer.c |    4 +-
 src/tracker-extract/tracker-extract-mp3.c       |   16 +++++--
 4 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/src/tracker-extract/tracker-extract-albumart.c b/src/tracker-extract/tracker-extract-albumart.c
index 206a836..9f1a93a 100644
--- a/src/tracker-extract/tracker-extract-albumart.c
+++ b/src/tracker-extract/tracker-extract-albumart.c
@@ -48,6 +48,7 @@
 static gboolean
 set_albumart (const unsigned char *buffer,
 	      size_t               len,
+	      const gchar         *mime,
 	      const gchar         *artist, 
 	      const gchar         *album,
 	      const gchar         *uri)
@@ -66,36 +67,40 @@ set_albumart (const unsigned char *buffer,
 
 	tracker_albumart_get_path (artist, album, "album", NULL, &filename, NULL);
 
-	loader = gdk_pixbuf_loader_new ();
+	if (g_strcmp0 (mime, "image/jpeg") == 0 || g_strcmp0 (mime, "JPG") == 0) {
+		g_file_set_contents (filename, buffer, (gssize) len, NULL);
+	} else {
+		loader = gdk_pixbuf_loader_new ();
 
-	if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
-		g_warning ("%s\n", error->message);
-		g_error_free (error);
+		if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
+			g_warning ("%s\n", error->message);
+			g_error_free (error);
 
-		gdk_pixbuf_loader_close (loader, NULL);
-		g_free (filename);
-		return FALSE;
-	}
+			gdk_pixbuf_loader_close (loader, NULL);
+			g_free (filename);
+			return FALSE;
+		}
 
-	pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+		pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
 
-	if (!gdk_pixbuf_save (pixbuf, filename, "jpeg", &error, NULL)) {
-		g_warning ("%s\n", error->message);
-		g_error_free (error);
+		if (!gdk_pixbuf_save (pixbuf, filename, "jpeg", &error, NULL)) {
+			g_warning ("%s\n", error->message);
+			g_error_free (error);
 
-		g_free (filename);
-		g_object_unref (pixbuf);
+			g_free (filename);
+			g_object_unref (pixbuf);
 
-		gdk_pixbuf_loader_close (loader, NULL);
-		return FALSE;
-	}
+			gdk_pixbuf_loader_close (loader, NULL);
+			return FALSE;
+		}
 
 
-	g_object_unref (pixbuf);
+		g_object_unref (pixbuf);
 
-	if (!gdk_pixbuf_loader_close (loader, &error)) {
-		g_warning ("%s\n", error->message);
-		g_error_free (error);
+		if (!gdk_pixbuf_loader_close (loader, &error)) {
+			g_warning ("%s\n", error->message);
+			g_error_free (error);
+		}
 	}
 
 	tracker_thumbnailer_queue_file (filename, "image/jpeg");
@@ -109,6 +114,7 @@ set_albumart (const unsigned char *buffer,
 gboolean
 tracker_process_albumart (const unsigned char *buffer,
                           size_t               len,
+                          const gchar         *buf_mime,
                           const gchar         *artist,
                           const gchar         *album,
                           const gchar         *trackercnt_str,
@@ -145,7 +151,7 @@ tracker_process_albumart (const unsigned char *buffer,
 		/* If we have embedded album art */
 		if (buffer && len) {
 			retval = set_albumart (buffer, 
-					       len,
+					       len, buf_mime,
 					       artist,
 					       album,
 					       filename);
diff --git a/src/tracker-extract/tracker-extract-albumart.h b/src/tracker-extract/tracker-extract-albumart.h
index c69b161..6d5db91 100644
--- a/src/tracker-extract/tracker-extract-albumart.h
+++ b/src/tracker-extract/tracker-extract-albumart.h
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
 
 gboolean tracker_process_albumart (const unsigned char *buffer,
                                    size_t               len,
+                                   const gchar         *buf_mime,
                                    const gchar         *artist,
                                    const gchar         *album,
                                    const gchar         *trackercnt_str,
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 9b7323c..444b3b0 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -749,13 +749,13 @@ tracker_extract_gstreamer (const gchar *uri,
 	/* Save embedded art */
 	if (extractor->album_art_data && extractor->album_art_size) {
 #ifdef HAVE_GDKPIXBUF
-		tracker_process_albumart (extractor->album_art_data, extractor->album_art_size,
+		tracker_process_albumart (extractor->album_art_data, extractor->album_art_size, NULL,
 					  /* g_hash_table_lookup (metadata, "Audio:Artist") */ NULL,
 					  g_hash_table_lookup (metadata, "Audio:Album"),
 					  g_hash_table_lookup (metadata, "Audio:AlbumTrackCount"),
 					  uri);
 #else
-		tracker_process_albumart (NULL, 0,
+		tracker_process_albumart (NULL, 0, NULL,
 					  /* g_hash_table_lookup (metadata, "Audio:Artist") */ NULL,
 					  g_hash_table_lookup (metadata, "Audio:Album"),
 					  g_hash_table_lookup (metadata, "Audio:AlbumTrackCount"),
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 070ee62..9b3f62d 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -87,6 +87,7 @@ typedef struct {
 
 	unsigned char *albumartdata;
 	size_t         albumartsize;
+	gchar         *albumartmime
 } file_data;
 
 enum {
@@ -978,6 +979,7 @@ get_id3v24_tags (const gchar *data,
 				offset = pos + 11 + mime_len + 2 + strlen (desc) + 1;
 
 				filedata->albumartdata = g_malloc0 (csize);
+				filedata->albumartmime = g_strdup (mime);
 				memcpy (filedata->albumartdata, &data[offset], csize);
 				filedata->albumartsize = csize;
 			}
@@ -1210,6 +1212,7 @@ get_id3v23_tags (const gchar *data,
 				offset = pos + 11 + mime_len + 2 + strlen (desc) + 1;
 				
 				filedata->albumartdata = g_malloc0 (csize);
+				filedata->albumartmime = g_strdup (mime);
 				memcpy (filedata->albumartdata, &data[offset], csize);
 				filedata->albumartsize = csize;
 			}
@@ -1362,13 +1365,16 @@ get_id3v20_tags (const gchar *data,
 			gchar          pic_type;
 			const gchar   *desc;
 			guint          offset;
+			const gchar   *mime;
 
+			mime      = &data[pos + 6 + 3 + 1];
 			pic_type  =  data[pos + 6 + 3 + 1 + 3];
 			desc      = &data[pos + 6 + 3 + 1 + 3 + 1];
 
 			if (pic_type == 3 || (pic_type == 0 && filedata->albumartsize == 0)) {
 				offset = pos + 6 + 3 + 1 + 3  + 1 + strlen (desc) + 1;
 
+				filedata->albumartmime = g_strdup (mime);
 				filedata->albumartdata = g_malloc0 (csize);
 				memcpy (filedata->albumartdata, &data[offset], csize);
 				filedata->albumartsize = csize;
@@ -1612,6 +1618,7 @@ extract_mp3 (const gchar *filename,
 	filedata.id3v2_size = 0;
 	filedata.duration = 0;
 	filedata.albumartdata = NULL;
+	filedata.albumartmime = NULL;
 	filedata.albumartsize = 0;
 
 	size = tracker_file_get_size (filename);
@@ -1724,13 +1731,13 @@ extract_mp3 (const gchar *filename,
 	mp3_parse (buffer, buffer_size, audio_offset, metadata, &filedata);
 
 #ifdef HAVE_GDKPIXBUF
-	tracker_process_albumart (filedata.albumartdata, filedata.albumartsize,
+	tracker_process_albumart (filedata.albumartdata, filedata.albumartsize, filedata.albumartmime,
 				  /* g_hash_table_lookup (metadata, "Audio:Artist") */ NULL,
 				  g_hash_table_lookup (metadata, "Audio:Album"),
 				  g_hash_table_lookup (metadata, "Audio:AlbumTrackCount"),
 				  filename);
 #else
-	tracker_process_albumart (NULL, 0,
+	tracker_process_albumart (NULL, 0, NULL,
 				  /* g_hash_table_lookup (metadata, "Audio:Artist") */ NULL,
 				  g_hash_table_lookup (metadata, "Audio:Album"),
 				  g_hash_table_lookup (metadata, "Audio:AlbumTrackCount"),
@@ -1738,9 +1745,8 @@ extract_mp3 (const gchar *filename,
 
 #endif /* HAVE_GDKPIXBUF */
 
-	if (filedata.albumartdata) {
-		g_free (filedata.albumartdata);
-	}
+	g_free (filedata.albumartdata);
+	g_free (filedata.albumartmime);
 
 	/* Check that we have the minimum data. FIXME We should not need to do this */
 	if (!g_hash_table_lookup (metadata, "Audio:Title")) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]