[tracker] tracker-extract: Sanitise the albumart code with an init/shutdown function
- From: Martyn James Russell <mr src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] tracker-extract: Sanitise the albumart code with an init/shutdown function
- Date: Mon, 27 Jul 2009 18:16:34 +0000 (UTC)
commit 9ee43347ce536cf8be33490e7b33859964182c09
Author: Martyn Russell <martyn imendio com>
Date: Mon Jul 27 11:10:21 2009 +0100
tracker-extract: Sanitise the albumart code with an init/shutdown function
Also added an initial dbus signal for tracker-extract to be able to
tell the tracker-miner-fs about new files that need thumbnailing.
data/dbus/tracker-extract.xml | 4 +
src/libtracker-common/tracker-albumart.c | 11 ++-
src/tracker-extract/Makefile.am | 38 +++----
src/tracker-extract/tracker-extract-albumart.c | 149 +++++++++++++----------
src/tracker-extract/tracker-extract-albumart.h | 27 ++--
src/tracker-extract/tracker-extract-gstreamer.c | 8 +-
src/tracker-extract/tracker-extract-mp3.c | 14 ++-
src/tracker-extract/tracker-extract.c | 18 +++
src/tracker-extract/tracker-main.c | 22 +---
src/tracker-extract/tracker-main.h | 6 -
10 files changed, 163 insertions(+), 134 deletions(-)
---
diff --git a/data/dbus/tracker-extract.xml b/data/dbus/tracker-extract.xml
index 8b2dc9d..65580bf 100644
--- a/data/dbus/tracker-extract.xml
+++ b/data/dbus/tracker-extract.xml
@@ -21,5 +21,9 @@
<arg type="s" name="mime" direction="in" />
<arg type="s" name="sparql" direction="out" />
</method>
+
+ <signal name="NeedsThumbnailing">
+ <arg type="s" name="uri"/>
+ </signal>
</interface>
</node>
diff --git a/src/libtracker-common/tracker-albumart.c b/src/libtracker-common/tracker-albumart.c
index 1221f01..5e07d40 100644
--- a/src/libtracker-common/tracker-albumart.c
+++ b/src/libtracker-common/tracker-albumart.c
@@ -389,6 +389,10 @@ tracker_albumart_heuristic (const gchar *artist_,
gchar *artist = NULL;
gchar *album = NULL;
+ if (copied) {
+ *copied = FALSE;
+ }
+
/* Copy from local album art (.mediaartlocal) to spec */
if (local_uri) {
GFile *local_file;
@@ -409,7 +413,10 @@ tracker_albumart_heuristic (const gchar *artist_,
}
g_object_unref (local_file);
- *copied = TRUE;
+ if (copied) {
+ *copied = TRUE;
+ }
+
g_free (target);
return TRUE;
@@ -418,8 +425,6 @@ tracker_albumart_heuristic (const gchar *artist_,
g_object_unref (local_file);
}
- *copied = FALSE;
-
file = g_file_new_for_path (filename);
dirf = g_file_get_parent (file);
dirname = g_file_get_path (dirf);
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index f9e48e1..510ac7d 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -105,20 +105,6 @@ iptc_sources = \
tracker-iptc.c \
tracker-iptc.h
-# Common AlbumArt sources
-
-albumart_libs =
-albumart_flags =
-albumart_sources = \
- tracker-extract-albumart.c \
- tracker-extract-albumart.h
-
-if HAVE_GDKPIXBUF
-albumart_flags += $(DBUS_CFLAGS)
-albumart_libs += \
- $(GDKPIXBUF_LIBS) $(DBUS_LIBS) $(GCOV_LIBS)
-endif
-
# ABW
libextract_abw_la_SOURCES = tracker-extract-abw.c
libextract_abw_la_LDFLAGS = $(module_flags)
@@ -126,9 +112,9 @@ libextract_abw_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS) \
$(top_builddir)/src/libtracker-common/libtracker-common.la
# MP3
-libextract_mp3_la_SOURCES = tracker-extract-mp3.c $(albumart_sources)
-libextract_mp3_la_LDFLAGS = $(module_flags) $(albumart_flags)
-libextract_mp3_la_LIBADD = $(albumart_libs) $(GLIB2_LIBS) $(GCOV_LIBS) \
+libextract_mp3_la_SOURCES = tracker-extract-mp3.c
+libextract_mp3_la_LDFLAGS = $(module_flags)
+libextract_mp3_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS) \
$(top_builddir)/src/libtracker-common/libtracker-common.la
if HAVE_ENCA
@@ -198,15 +184,15 @@ libextract_pdf_la_LIBADD = $(GLIB2_LIBS) $(POPPLER_GLIB_LIBS) $(EXEMPI_LIBS) $(G
$(top_builddir)/src/libtracker-common/libtracker-common.la
# GStreamer
-libextract_gstreamer_la_SOURCES = tracker-extract-gstreamer.c $(albumart_sources)
-libextract_gstreamer_la_LDFLAGS = $(module_flags) $(albumart_flags)
-libextract_gstreamer_la_LIBADD = $(albumart_libs) $(GSTREAMER_LIBS) $(GLIB2_LIBS) $(GCOV_LIBS) \
+libextract_gstreamer_la_SOURCES = tracker-extract-gstreamer.c
+libextract_gstreamer_la_LDFLAGS = $(module_flags)
+libextract_gstreamer_la_LIBADD = $(GSTREAMER_LIBS) $(GLIB2_LIBS) $(GCOV_LIBS) \
$(top_builddir)/src/libtracker-common/libtracker-common.la
# GStreamer helix
-libextract_gstreamer_helix_la_SOURCES = tracker-extract-gstreamer-helix.c $(albumart_sources)
+libextract_gstreamer_helix_la_SOURCES = tracker-extract-gstreamer-helix.c
libextract_gstreamer_helix_la_LDFLAGS = $(module_flags) $(albumart_flags)
-libextract_gstreamer_helix_la_LIBADD = $(albumart_libs) $(GSTREAMER_LIBS) $(GLIB2_LIBS) $(GCOV_LIBS) \
+libextract_gstreamer_helix_la_LIBADD = $(GSTREAMER_LIBS) $(GLIB2_LIBS) $(GCOV_LIBS) \
$(top_builddir)/src/libtracker-common/libtracker-common.la
# Xine
@@ -240,7 +226,6 @@ libextract_playlist_la_LIBADD = $(GLIB2_LIBS) $(TOTEM_PL_PARSER_LIBS) $(GCOV_LIB
$(top_builddir)/src/libtracker-common/libtracker-common.la
-
#
# Binaries
#
@@ -253,17 +238,24 @@ tracker_extract_SOURCES = \
tracker-dbus.h \
tracker-extract.c \
tracker-extract.h \
+ tracker-extract-albumart.c \
+ tracker-extract-albumart.h \
tracker-main.c \
tracker-main.h
tracker_extract_LDADD = \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(DBUS_LIBS) \
$(GMODULE_LIBS) \
$(GTHREAD_LIBS) \
$(GCOV_LIBS) \
$(GLIB2_LIBS) \
$(STREAMANALYZER_LIBS)
+if HAVE_GDKPIXBUF
+tracker_extract_LDADD += $(GDKPIXBUF_LIBS)
+endif
+
if HAVE_STREAMANALYZER
tracker_extract_SOURCES += tracker-topanalyzer.cpp tracker-topanalyzer.h
tracker_extract_LDADD += $(STREAMANALYZER_LIBS)
diff --git a/src/tracker-extract/tracker-extract-albumart.c b/src/tracker-extract/tracker-extract-albumart.c
index 6ac17e6..fe35df0 100644
--- a/src/tracker-extract/tracker-extract-albumart.c
+++ b/src/tracker-extract/tracker-extract-albumart.c
@@ -37,13 +37,14 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
-#include <libtracker-common/tracker-common.h>
#include <libtracker-common/tracker-thumbnailer.h>
+#include <libtracker-common/tracker-albumart.h>
#include "tracker-main.h"
#include "tracker-extract-albumart.h"
-static GHashTable *album_art_done = NULL;
+static GHashTable *albumart;
+static TrackerStorage *hal;
#ifdef HAVE_GDKPIXBUF
@@ -53,14 +54,17 @@ set_albumart (const unsigned char *buffer,
const gchar *mime,
const gchar *artist,
const gchar *album,
- const gchar *uri)
+ const gchar *uri,
+ gboolean *was_thumbnail_queued)
{
GdkPixbufLoader *loader;
GdkPixbuf *pixbuf = NULL;
gchar *filename;
GError *error = NULL;
- g_type_init ();
+ if (was_thumbnail_queued) {
+ *was_thumbnail_queued = FALSE;
+ }
if (!artist && !album) {
g_warning ("No identification data for embedded image");
@@ -69,42 +73,50 @@ set_albumart (const unsigned char *buffer,
tracker_albumart_get_path (artist, album, "album", NULL, &filename, NULL);
- if (g_strcmp0 (mime, "image/jpeg") == 0 || g_strcmp0 (mime, "JPG") == 0) {
+ 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);
+ g_warning ("Could not write with GdkPixbufLoader when setting album art, %s",
+ error ? error->message : "no error given");
+ g_clear_error (&error);
gdk_pixbuf_loader_close (loader, NULL);
g_free (filename);
+
return FALSE;
}
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);
+ g_warning ("Could not save GdkPixbuf when setting album art, %s",
+ error ? error->message : "no error given");
+ g_clear_error (&error);
g_free (filename);
g_object_unref (pixbuf);
-
gdk_pixbuf_loader_close (loader, NULL);
+
return FALSE;
}
-
g_object_unref (pixbuf);
if (!gdk_pixbuf_loader_close (loader, &error)) {
- g_warning ("%s\n", error->message);
- g_error_free (error);
+ g_warning ("Could not close GdkPixbufLoader when setting album art, %s",
+ error ? error->message : "no error given");
+ g_clear_error (&error);
}
}
+ if (was_thumbnail_queued) {
+ *was_thumbnail_queued = TRUE;
+ }
+
tracker_thumbnailer_queue_file (filename, "image/jpeg");
g_free (filename);
@@ -113,24 +125,46 @@ set_albumart (const unsigned char *buffer,
#endif /* HAVE_GDKPIXBUF */
+void
+tracker_albumart_init (void)
+{
+ g_type_init ();
+
+ albumart = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+
+#ifdef HAVE_HAL
+ hal = tracker_storage_new ();
+#else
+ hal = NULL;
+#endif
+}
+
+void
+tracker_albumart_shutdown (void)
+{
+ g_hash_table_unref (albumart);
+}
+
gboolean
-tracker_process_albumart (const unsigned char *buffer,
+tracker_albumart_process (const unsigned char *buffer,
size_t len,
- const gchar *buf_mime,
+ const gchar *mime,
const gchar *artist,
const gchar *album,
const gchar *trackercnt_str,
const gchar *filename)
{
gchar *art_path;
- gboolean retval = TRUE;
+ gboolean processed = TRUE;
gchar *local_uri = NULL;
gchar *filename_uri;
- gboolean lcopied = FALSE;
gboolean art_exists;
- gchar *as_uri;
+ gboolean was_thumbnail_queued;
- if (strchr (filename, ':')) {
+ if (strstr (filename, "://")) {
filename_uri = g_strdup (filename);
} else {
filename_uri = g_filename_to_uri (filename, NULL, NULL);
@@ -156,14 +190,13 @@ tracker_process_albumart (const unsigned char *buffer,
#ifdef HAVE_GDKPIXBUF
/* If we have embedded album art */
if (buffer && len) {
- retval = set_albumart (buffer,
- len, buf_mime,
- artist,
- album,
- filename);
-
- lcopied = !retval;
-
+ processed = set_albumart (buffer,
+ len,
+ mime,
+ artist,
+ album,
+ filename,
+ &was_thumbnail_queued);
} else {
#endif /* HAVE_GDK_PIXBUF */
/* If not, we perform a heuristic on the dir */
@@ -177,47 +210,35 @@ tracker_process_albumart (const unsigned char *buffer,
g_object_unref (file);
g_object_unref (dirf);
- key = g_strdup_printf ("%s-%s-%s", artist ? artist : "",
+ key = g_strdup_printf ("%s-%s-%s",
+ artist ? artist : "",
album ? album : "",
dirname ? dirname : "");
g_free (dirname);
- /* We store these in a table because we want to avoid
- * that we do many requests for the same directory
- * subsequently without success. It's a small but
- * known leak on the variable "key" and the hashtable
- * itself.
- *
- * We could get rid of the leak by having a shutdown
- * function for extract modules. I don't think this
- * mini leak is enough reason to add such shutdown
- * infrastructure to the extract modules. */
-
- if (!album_art_done) {
- album_art_done = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
- }
-
- if (!g_hash_table_lookup (album_art_done, key)) {
- if (!tracker_albumart_heuristic (artist, album,
+ if (!g_hash_table_lookup (albumart, key)) {
+ if (!tracker_albumart_heuristic (artist,
+ album,
trackercnt_str,
filename,
local_uri,
- &lcopied)) {
-
- /* If the heuristic failed, we request the download
- * of the media-art to the media-art downloaders */
- lcopied = TRUE;
- tracker_albumart_request_download (tracker_main_get_hal (),
+ NULL)) {
+ /* If the heuristic failed, we
+ * request the download the
+ * media-art to the media-art
+ * downloaders
+ */
+ tracker_albumart_request_download (hal,
artist,
album,
local_uri,
art_path);
}
- g_hash_table_insert (album_art_done, key, GINT_TO_POINTER(TRUE));
+
+ g_hash_table_insert (albumart,
+ key,
+ GINT_TO_POINTER(TRUE));
} else {
g_free (key);
}
@@ -225,17 +246,18 @@ tracker_process_albumart (const unsigned char *buffer,
}
#endif /* HAVE_GDKPIXBUF */
- as_uri = g_filename_to_uri (art_path, NULL, NULL);
- tracker_thumbnailer_queue_file (as_uri, "image/jpeg");
- g_free (as_uri);
-
+ if (!was_thumbnail_queued) {
+ was_thumbnail_queued = TRUE;
+ tracker_thumbnailer_queue_file (filename_uri, "image/jpeg");
+ }
}
if (local_uri && !g_file_test (local_uri, G_FILE_TEST_EXISTS)) {
- /* We can't reuse art_exists here because the situation might
- * have changed */
+ /* We can't reuse art_exists here because the
+ * situation might have changed
+ */
if (g_file_test (art_path, G_FILE_TEST_EXISTS)) {
- tracker_albumart_copy_to_local (tracker_main_get_hal (),
+ tracker_albumart_copy_to_local (hal,
art_path,
local_uri);
}
@@ -245,6 +267,5 @@ tracker_process_albumart (const unsigned char *buffer,
g_free (filename_uri);
g_free (local_uri);
- return retval;
+ return processed;
}
-
diff --git a/src/tracker-extract/tracker-extract-albumart.h b/src/tracker-extract/tracker-extract-albumart.h
index 6d5db91..5c69c07 100644
--- a/src/tracker-extract/tracker-extract-albumart.h
+++ b/src/tracker-extract/tracker-extract-albumart.h
@@ -1,4 +1,5 @@
-/* Tracker Xmp - Album art helper functions
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2008, Nokia
*
* This program is free software; you can redistribute it and/or
@@ -17,23 +18,23 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __TRACKER_ALBUMART_H__
-#define __TRACKER_ALBUMART_H__
+#ifndef __TRACKER_EXTRACT_ALBUMART_H__
+#define __TRACKER_EXTRACT_ALBUMART_H__
#include <glib.h>
-#include <libtracker-common/tracker-albumart.h>
-
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,
- const gchar *uri);
+void tracker_albumart_init (void);
+void tracker_albumart_shutdown (void);
+gboolean tracker_albumart_process (const unsigned char *buffer,
+ size_t len,
+ const gchar *buf_mime,
+ const gchar *artist,
+ const gchar *album,
+ const gchar *trackercnt_str,
+ const gchar *uri);
G_END_DECLS
-#endif /* __TRACKER_ALBUMART_H__ */
+#endif /* __TRACKER_EXTRACT_ALBUMART_H__ */
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 49d0378..8e06326 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -904,13 +904,17 @@ 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, extractor->album_art_mime,
+ tracker_albumart_process (extractor->album_art_data,
+ extractor->album_art_size,
+ extractor->album_art_mime,
/* g_hash_table_lookup (metadata, "Audio:Artist") */ NULL,
album,
scount,
uri);
#else
- tracker_process_albumart (NULL, 0, NULL,
+ tracker_albumart_process (NULL,
+ 0,
+ NULL,
/* g_hash_table_lookup (metadata, "Audio:Artist") */ NULL,
album,
scount,
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index e97c5ef..da4b7ea 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -1967,14 +1967,20 @@ extract_mp3 (const gchar *uri,
/* TODO */
#ifdef HAVE_GDKPIXBUF
- tracker_process_albumart (filedata.albumartdata, filedata.albumartsize, filedata.albumartmime,
+ tracker_albumart_process (filedata.albumartdata,
+ filedata.albumartsize,
+ filedata.albumartmime,
/* tracker_statement_list_find (metadata, NMM_PREFIX "performer") */ NULL,
- filedata.title, "-1",
+ filedata.title,
+ "-1",
filename);
#else
- tracker_process_albumart (NULL, 0, NULL,
+ tracker_albumart_process (NULL,
+ 0,
+ NULL,
/* tracker_statement_list_find (metadata, NMM_PREFIX "performer") */ NULL,
- filedata.title, "-1",
+ filedata.title,
+ "-1",
filename);
#endif /* HAVE_GDKPIXBUF */
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 66ab58e..add97bf 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -53,8 +53,15 @@ typedef struct {
const TrackerExtractData *edata;
} ModuleData;
+enum {
+ NEEDS_THUMBNAILING,
+ LAST_SIGNAL
+};
+
static void tracker_extract_finalize (GObject *object);
+static guint signals[LAST_SIGNAL] = {0};
+
G_DEFINE_TYPE(TrackerExtract, tracker_extract, G_TYPE_OBJECT)
static void
@@ -66,6 +73,17 @@ tracker_extract_class_init (TrackerExtractClass *klass)
object_class->finalize = tracker_extract_finalize;
+ signals[NEEDS_THUMBNAILING] =
+ g_signal_new ("needs-thumbnailing",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_STRING);
+
g_type_class_add_private (object_class, sizeof (TrackerExtractPrivate));
}
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index 89b6adc..0c35e8e 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -49,6 +49,7 @@
#include <libtracker-common/tracker-thumbnailer.h>
#include <libtracker-common/tracker-ioprio.h>
+#include "tracker-extract-albumart.h"
#include "tracker-config.h"
#include "tracker-main.h"
#include "tracker-dbus.h"
@@ -68,7 +69,6 @@
static GMainLoop *main_loop;
static guint quit_timeout_id = 0;
-static TrackerStorage *hal;
static gboolean version;
gboolean debug = FALSE;
@@ -130,20 +130,6 @@ tracker_main_quit_timeout_reset (void)
NULL);
}
-TrackerStorage *
-tracker_main_get_hal (void)
-{
- if (!hal) {
-#ifdef HAVE_HAL
- hal = tracker_storage_new ();
-#else
- hal = NULL;
-#endif
- }
-
- return hal;
-}
-
static void
initialize_priority (void)
{
@@ -389,6 +375,7 @@ main (int argc, char *argv[])
g_print ("Starting log:\n File:'%s'\n", log_filename);
g_free (log_filename);
+ tracker_albumart_init ();
tracker_thumbnailer_init ();
/* Make Tracker available for introspection */
@@ -408,16 +395,13 @@ main (int argc, char *argv[])
/* Push all items in thumbnail queue to the thumbnailer */
tracker_thumbnailer_queue_send ();
+ tracker_albumart_shutdown ();
/* Shutdown subsystems */
tracker_dbus_shutdown ();
tracker_thumbnailer_shutdown ();
tracker_log_shutdown ();
- if (hal) {
- g_object_unref (hal);
- }
-
g_object_unref (config);
done:
diff --git a/src/tracker-extract/tracker-main.h b/src/tracker-extract/tracker-main.h
index d1513cf..45c5405 100644
--- a/src/tracker-extract/tracker-main.h
+++ b/src/tracker-extract/tracker-main.h
@@ -43,12 +43,6 @@ struct TrackerExtractData {
/* This is defined in each extract */
TrackerExtractData *tracker_get_extract_data (void);
-/* Some modules need to use the albumart API which requires HAL. To
- * avoid creating new HAL objects constantly, we initialize it once
- * and it is available using this API.
- */
-TrackerStorage * tracker_main_get_hal (void);
-
/* This is used to not shutdown after the default of 30 seconds if we
* get more work to do.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]