summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-05-08 17:44:09 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-05-08 17:44:09 +0200
commit24eeb7ee096fd1066c4b6aa15a67be369958825d (patch)
tree92a11d0f2d5a8a1b3dbca1360d2d66ea6577b020
parent40216453411e800a3aa6cc13079c1548c27d0b20 (diff)
fixed possible hangs / errors in artwork plugin
-rw-r--r--plugins/artwork/albumartorg.c5
-rw-r--r--plugins/artwork/artwork.c11
-rw-r--r--plugins/artwork/artwork.h2
-rw-r--r--plugins/artwork/lastfm.c5
-rw-r--r--plugins/gtkui/gtkui.c4
5 files changed, 27 insertions, 0 deletions
diff --git a/plugins/artwork/albumartorg.c b/plugins/artwork/albumartorg.c
index cc10f235..31a0c32f 100644
--- a/plugins/artwork/albumartorg.c
+++ b/plugins/artwork/albumartorg.c
@@ -42,6 +42,7 @@ fetch_from_albumart_org (const char *artist, const char *album, const char *dest
trace ("fetch_from_albumart_org: failed to open %s\n", url);
return -1;
}
+ current_file = fp;
const char searchstr[] = "http://ecx.images-amazon.com/images/I/";
char buffer[10000];
memset (buffer, 0, sizeof (buffer));
@@ -50,6 +51,7 @@ fetch_from_albumart_org (const char *artist, const char *album, const char *dest
if (size > 0) {
img = strstr (buffer, searchstr);
}
+ current_file = NULL;
deadbeef->fclose (fp);
if (!img) {
@@ -70,10 +72,12 @@ fetch_from_albumart_org (const char *artist, const char *album, const char *dest
trace ("fetch_from_albumart_org: failed to open %s\n", img);
return -1;
}
+ current_file = fp;
FILE *out = fopen (dest, "w+b");
if (!out) {
trace ("fetch_from_albumart_org: failed to open %s for writing\n", dest);
+ current_file = NULL;
deadbeef->fclose (fp);
return -1;
}
@@ -90,6 +94,7 @@ fetch_from_albumart_org (const char *artist, const char *album, const char *dest
}
fclose (out);
+ current_file = NULL;
deadbeef->fclose (fp);
if (error) {
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c
index 9aba5351..da4b1a8f 100644
--- a/plugins/artwork/artwork.c
+++ b/plugins/artwork/artwork.c
@@ -20,6 +20,8 @@
static DB_artwork_plugin_t plugin;
DB_functions_t *deadbeef;
+DB_FILE *current_file;
+
typedef struct cover_query_s {
char *fname;
char *artist;
@@ -268,6 +270,7 @@ fetcher_thread (void *none)
DB_id3v2_tag_t tag;
memset (&tag, 0, sizeof (tag));
DB_FILE *fp = deadbeef->fopen (param->fname);
+ current_file = fp;
int got_id3v2_pic = 0;
if (fp) {
int res = deadbeef->junk_id3v2_read_full (NULL, &tag, fp);
@@ -345,6 +348,7 @@ fetcher_thread (void *none)
continue;
}
deadbeef->junk_id3v2_free (&tag);
+ current_file = NULL;
deadbeef->fclose (fp);
}
}
@@ -483,6 +487,9 @@ artwork_load (DB_functions_t *api) {
void
artwork_reset (int fast) {
if (fast) {
+ if (current_file) {
+ deadbeef->fabort (current_file);
+ }
deadbeef->mutex_lock (mutex);
while (queue && queue->next) {
cover_query_t *next = queue->next->next;
@@ -521,6 +528,9 @@ artwork_plugin_start (void)
static int
artwork_plugin_stop (void)
{
+ if (current_file) {
+ deadbeef->fabort (current_file);
+ }
if (tid) {
terminate = 1;
deadbeef->cond_signal (cond);
@@ -536,6 +546,7 @@ artwork_plugin_stop (void)
}
if (cond) {
deadbeef->cond_free (cond);
+ cond = 0;
}
return 0;
diff --git a/plugins/artwork/artwork.h b/plugins/artwork/artwork.h
index c6fd9177..ab0fead6 100644
--- a/plugins/artwork/artwork.h
+++ b/plugins/artwork/artwork.h
@@ -3,6 +3,8 @@
#include "../../deadbeef.h"
+extern DB_FILE *current_file;
+
typedef void (*artwork_callback) (const char *fname, const char *artist, const char *album, void *user_data);
typedef struct {
diff --git a/plugins/artwork/lastfm.c b/plugins/artwork/lastfm.c
index 6f429bf7..83530ffd 100644
--- a/plugins/artwork/lastfm.c
+++ b/plugins/artwork/lastfm.c
@@ -29,6 +29,7 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest)
trace ("fetch_from_lastfm: failed to open %s\n", url);
return -1;
}
+ current_file = fp;
const char searchstr[] = "<image size=\"extralarge\">";
char buffer[1000];
@@ -38,6 +39,7 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest)
if (size > 0) {
img = strstr (buffer, searchstr);
}
+ current_file = NULL;
deadbeef->fclose (fp);
if (!img) {
@@ -60,11 +62,13 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest)
trace ("fetch_from_lastfm: failed to open %s\n", img);
return -1;
}
+ current_file = fp;
FILE *out = fopen (dest, "w+b");
if (!out) {
trace ("fetch_from_lastfm: failed to open %s for writing\n", dest);
deadbeef->fclose (fp);
+ current_file = NULL;
return -1;
}
@@ -80,6 +84,7 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest)
}
fclose (out);
+ current_file = NULL;
deadbeef->fclose (fp);
if (error) {
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index 7f97791f..6a077830 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -870,6 +870,10 @@ quit_gtk_cb (gpointer nothing) {
static int
gtkui_stop (void) {
+ if (coverart_plugin) {
+ coverart_plugin->plugin.plugin.stop ();
+ coverart_plugin = NULL;
+ }
trace ("unsubscribing events\n");
deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_ACTIVATE, DB_CALLBACK (gtkui_on_activate), 0);
deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (gtkui_on_songchanged), 0);