diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/gtkui/gtkui.c | 6 | ||||
-rw-r--r-- | plugins/gtkui/plcommon.c | 12 | ||||
-rw-r--r-- | plugins/gtkui/trkproperties.c | 18 | ||||
-rw-r--r-- | plugins/lastfm/lastfm.c | 93 | ||||
-rw-r--r-- | plugins/mpgmad/mpgmad.c | 23 | ||||
-rw-r--r-- | plugins/shellexec/shellexec.c | 2 |
6 files changed, 90 insertions, 64 deletions
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 7ded4f6d..b96eb301 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -192,9 +192,9 @@ update_songinfo (gpointer ctx) { } } const char *spaused = deadbeef->get_output ()->state () == OUTPUT_STATE_PAUSED ? _("Paused | ") : ""; - const char *filetype = deadbeef->pl_find_meta (track, ":FILETYPE"); - if (!filetype) { - filetype = "-"; + char filetype[20]; + if (!deadbeef->pl_get_meta (track, ":FILETYPE", filetype, sizeof (filetype))) { + strcpy (filetype, "-"); } snprintf (sbtext_new, sizeof (sbtext_new), _("%s%s %s| %dHz | %d bit | %s | %d:%02d / %s | %d tracks | %s total playtime"), spaused, filetype, sbitrate, samplerate, bitspersample, mode, minpos, secpos, t, deadbeef->pl_getcount (PL_MAIN), totaltime_str); } diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c index 406b2f16..f0c36a24 100644 --- a/plugins/gtkui/plcommon.c +++ b/plugins/gtkui/plcommon.c @@ -256,8 +256,16 @@ main_reload_metadata_activate DdbListview *ps = DDB_LISTVIEW (g_object_get_data (G_OBJECT (menuitem), "ps")); DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); while (it) { - const char *decoder_id = deadbeef->pl_find_meta (it, ":DECODER"); - if (deadbeef->pl_is_selected (it) && deadbeef->is_local_file (deadbeef->pl_find_meta (it, ":URI")) && decoder_id) { + deadbeef->pl_lock (); + char decoder_id[100]; + const char *dec = deadbeef->pl_find_meta (it, ":DECODER"); + if (dec) { + strncpy (decoder_id, dec, sizeof (decoder_id)); + } + int match = deadbeef->pl_is_selected (it) && deadbeef->is_local_file (deadbeef->pl_find_meta (it, ":URI")) && dec; + deadbeef->pl_unlock (); + + if (match) { uint32_t f = deadbeef->pl_get_item_flags (it); if (!(f & DDB_IS_SUBTRACK)) { f &= ~DDB_TAG_MASK; diff --git a/plugins/gtkui/trkproperties.c b/plugins/gtkui/trkproperties.c index 590bf1fa..75b1f256 100644 --- a/plugins/gtkui/trkproperties.c +++ b/plugins/gtkui/trkproperties.c @@ -107,6 +107,7 @@ get_field_value (char *out, int size, const char *key, const char *(*getter)(DB_ return 0; } char *p = out; + deadbeef->pl_lock (); const char **prev = malloc (sizeof (const char *) * numtracks); memset (prev, 0, sizeof (const char *) * numtracks); for (int i = 0; i < numtracks; i++) { @@ -142,6 +143,7 @@ get_field_value (char *out, int size, const char *key, const char *(*getter)(DB_ break; } } + deadbeef->pl_unlock (); if (size <= 1) { gchar *prev = g_utf8_prev_char (out-4); strcpy (prev, "..."); @@ -491,8 +493,9 @@ static gboolean set_progress_cb (void *ctx) { DB_playItem_t *track = ctx; GtkWidget *progressitem = lookup_widget (progressdlg, "progresstitle"); - const char *fname = deadbeef->pl_find_meta_raw (track, ":URI"); - gtk_entry_set_text (GTK_ENTRY (progressitem), fname); + deadbeef->pl_lock (); + gtk_entry_set_text (GTK_ENTRY (progressitem), deadbeef->pl_find_meta_raw (track, ":URI")); + deadbeef->pl_unlock (); deadbeef->pl_item_unref (track); return FALSE; } @@ -504,8 +507,15 @@ write_meta_worker (void *ctx) { break; } DB_playItem_t *track = tracks[t]; - const char *decoder_id = deadbeef->pl_find_meta_raw (track, ":DECODER"); - if (track && decoder_id) { + deadbeef->pl_lock (); + const char *dec = deadbeef->pl_find_meta_raw (track, ":DECODER"); + char decoder_id[100]; + if (dec) { + strncpy (decoder_id, dec, sizeof (decoder_id)); + } + int match = track && dec; + deadbeef->pl_unlock (); + if (match) { int is_subtrack = deadbeef->pl_get_item_flags (track) & DDB_IS_SUBTRACK; if (is_subtrack) { continue; diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c index 8ab6c5f8..1e4fec70 100644 --- a/plugins/lastfm/lastfm.c +++ b/plugins/lastfm/lastfm.c @@ -49,6 +49,8 @@ static uintptr_t lfm_cond; static int lfm_stopthread; static intptr_t lfm_tid; +#define META_FIELD_SIZE 200 + DB_plugin_t * lastfm_load (DB_functions_t *api) { deadbeef = api; @@ -317,50 +319,41 @@ fail: } static int -lfm_fetch_song_info (DB_playItem_t *song, const char **a, const char **t, const char **b, float *l, const char **n, const char **m) { +lfm_fetch_song_info (DB_playItem_t *song, char *a, char *t, char *b, float *l, char *n, char *m) { if (deadbeef->conf_get_int ("lastfm.prefer_album_artist", 0)) { - *a = deadbeef->pl_find_meta (song, "band"); - if (!(*a)) { - *a = deadbeef->pl_find_meta (song, "album artist"); - } - if (!(*a)) { - *a = deadbeef->pl_find_meta (song, "albumartist"); - } - if (!(*a)) { - *a = deadbeef->pl_find_meta (song, "artist"); + if (!deadbeef->pl_get_meta (song, "band", a, META_FIELD_SIZE)) { + if (!deadbeef->pl_get_meta (song, "album artist", a, META_FIELD_SIZE)) { + if (!deadbeef->pl_get_meta (song, "albumartist", a, META_FIELD_SIZE)) { + if (!deadbeef->pl_get_meta (song, "artist", a, META_FIELD_SIZE)) { + return -1; + } + } + } } } else { - *a = deadbeef->pl_find_meta (song, "artist"); - if (!(*a)) { - *a = deadbeef->pl_find_meta (song, "band"); - } - if (!(*a)) { - *a = deadbeef->pl_find_meta (song, "album artist"); - } - if (!(*a)) { - *a = deadbeef->pl_find_meta (song, "albumartist"); + if (!deadbeef->pl_get_meta (song, "artist", a, META_FIELD_SIZE)) { + if (!deadbeef->pl_get_meta (song, "band", a, META_FIELD_SIZE)) { + if (!deadbeef->pl_get_meta (song, "album artist", a, META_FIELD_SIZE)) { + if (!deadbeef->pl_get_meta (song, "albumartist", a, META_FIELD_SIZE)) { + return -1; + } + } + } } } - if (!*a) { - return -1; - } - *t = deadbeef->pl_find_meta (song, "title"); - if (!*t) { + if (!deadbeef->pl_get_meta (song, "title", t, META_FIELD_SIZE)) { return -1; } - *b = deadbeef->pl_find_meta (song, "album"); - if (!*b) { - *b = ""; + if (!deadbeef->pl_get_meta (song, "album", b, META_FIELD_SIZE)) { + *b = 0; } *l = deadbeef->pl_get_item_duration (song); - *n = deadbeef->pl_find_meta (song, "track"); - if (!*n) { - *n = ""; + if (!deadbeef->pl_get_meta (song, "track", n, META_FIELD_SIZE)) { + *n = 0; } - *m = deadbeef->pl_find_meta (song, "mbid"); - if (!*m) { - *m = ""; + if (!deadbeef->pl_get_meta (song, "mbid", m, META_FIELD_SIZE)) { + *m = 0; } return 0; } @@ -443,12 +436,12 @@ lfm_format_uri (int subm, DB_playItem_t *song, char *out, int outl, time_t start return -1; } int sz = outl; - const char *a; // artist - const char *t; // title - const char *b; // album + char a[META_FIELD_SIZE]; // artist + char t[META_FIELD_SIZE]; // title + char b[META_FIELD_SIZE]; // album float l; // duration - const char *n; // tracknum - const char *m; // muzicbrainz id + char n[META_FIELD_SIZE]; // tracknum + char m[META_FIELD_SIZE]; // muzicbrainz id char ka[6] = "a"; char kt[6] = "t"; @@ -466,7 +459,7 @@ lfm_format_uri (int subm, DB_playItem_t *song, char *out, int outl, time_t start strcpy (km+1, ka+1); } - if (lfm_fetch_song_info (song, &a, &t, &b, &l, &n, &m) == 0) { + if (lfm_fetch_song_info (song, a, t, b, &l, n, m) == 0) { // trace ("playtime: %f\nartist: %s\ntitle: %s\nalbum: %s\nduration: %f\ntracknum: %s\n---\n", song->playtime, a, t, b, l, n); } else { @@ -559,9 +552,8 @@ lastfm_songchanged (ddb_event_trackchange_t *ev, uintptr_t data) { #endif - if (!deadbeef->pl_find_meta (ev->from, "artist") - || !deadbeef->pl_find_meta (ev->from, "title") -// || !deadbeef->pl_find_meta (ev->from, "album") + if (!deadbeef->pl_meta_exists (ev->from, "artist") + || !deadbeef->pl_meta_exists (ev->from, "title") ) { trace ("lfm: not enough metadata for submission, artist=%s, title=%s, album=%s\n", deadbeef->pl_find_meta (ev->from, "artist"), deadbeef->pl_find_meta (ev->from, "title"), deadbeef->pl_find_meta (ev->from, "album")); return 0; @@ -876,11 +868,14 @@ lastfm_stop (void) { static int lfm_action_lookup (DB_plugin_action_t *action, DB_playItem_t *it) { - const char *artist = deadbeef->pl_find_meta (it, "artist"); - const char *title = deadbeef->pl_find_meta (it, "title"); - - if (!title || !artist) + char artist[META_FIELD_SIZE]; + if (!deadbeef->pl_get_meta (it, "artist", artist, sizeof (artist))) { + return 0; + } + char title[META_FIELD_SIZE]; + if (!deadbeef->pl_get_meta (it, "title", title, sizeof (title))) { return 0; + } char eartist [strlen (artist) * 3 + 1]; char etitle [strlen (title) * 3 + 1]; @@ -925,9 +920,10 @@ static DB_plugin_action_t lookup_action = { static DB_plugin_action_t * lfm_get_actions (DB_playItem_t *it) { + deadbeef->pl_lock (); if (!it || - !deadbeef->pl_find_meta (it, "artist") || - !deadbeef->pl_find_meta (it, "title")) + !deadbeef->pl_meta_exists (it, "artist") || + !deadbeef->pl_meta_exists (it, "title")) { love_action.flags |= DB_ACTION_DISABLED; lookup_action.flags |= DB_ACTION_DISABLED; @@ -937,6 +933,7 @@ lfm_get_actions (DB_playItem_t *it) love_action.flags &= ~DB_ACTION_DISABLED; lookup_action.flags &= ~DB_ACTION_DISABLED; } + deadbeef->pl_unlock (); return &lookup_action; } diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c index 32f4022f..0e06bbeb 100644 --- a/plugins/mpgmad/mpgmad.c +++ b/plugins/mpgmad/mpgmad.c @@ -793,7 +793,9 @@ cmp3_init (DB_fileinfo_t *_info, DB_playItem_t *it) { mpgmad_info_t *info = (mpgmad_info_t *)_info; _info->plugin = &plugin; memset (&info->buffer, 0, sizeof (info->buffer)); + deadbeef->pl_lock (); info->buffer.file = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI")); + deadbeef->pl_unlock (); if (!info->buffer.file) { return -1; } @@ -1357,15 +1359,20 @@ cmp3_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { deadbeef->plt_set_item_duration (plt, it, buffer.duration); deadbeef->fclose (fp); - const char *cuesheet = deadbeef->pl_find_meta (it, "cuesheet"); - if (cuesheet) { - DB_playItem_t *last = deadbeef->plt_insert_cue_from_buffer (plt, after, it, cuesheet, strlen (cuesheet), buffer.totalsamples-buffer.delay-buffer.padding, buffer.samplerate); - if (last) { - deadbeef->pl_item_unref (it); - deadbeef->pl_item_unref (last); - return last; + deadbeef->pl_lock (); + { + const char *cuesheet = deadbeef->pl_find_meta (it, "cuesheet"); + if (cuesheet) { + DB_playItem_t *last = deadbeef->plt_insert_cue_from_buffer (plt, after, it, cuesheet, strlen (cuesheet), buffer.totalsamples-buffer.delay-buffer.padding, buffer.samplerate); + deadbeef->pl_unlock (); + if (last) { + deadbeef->pl_item_unref (it); + deadbeef->pl_item_unref (last); + return last; + } } } + deadbeef->pl_unlock (); // FIXME! bad numsamples passed to cue @@ -1383,7 +1390,9 @@ cmp3_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { int cmp3_read_metadata (DB_playItem_t *it) { + deadbeef->pl_lock (); DB_FILE *fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI")); + deadbeef->pl_unlock (); if (!fp) { return -1; } diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c index b419a4c9..7d49c2d6 100644 --- a/plugins/shellexec/shellexec.c +++ b/plugins/shellexec/shellexec.c @@ -103,7 +103,9 @@ shx_callback (Shx_action_t *action, DB_playItem_t *it) static DB_plugin_action_t * shx_get_plugin_actions (DB_playItem_t *it) { + deadbeef->pl_lock (); int is_local = it ? deadbeef->is_local_file (deadbeef->pl_find_meta (it, ":URI")) : 1; + deadbeef->pl_unlock (); Shx_action_t *action; for (action = actions; action; action = (Shx_action_t *)action->parent.next) |