summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deadbeef.h3
-rw-r--r--playlist.c33
-rw-r--r--playlist.h9
-rw-r--r--plugins.c3
-rw-r--r--plugins/ffap/ffap.c4
-rw-r--r--plugins/ffmpeg/ffmpeg.c2
-rw-r--r--plugins/flac/flac.c4
-rw-r--r--plugins/lastfm/lastfm.c4
-rw-r--r--plugins/mpgmad/mpgmad.c2
-rw-r--r--plugins/vorbis/vorbis.c4
-rw-r--r--plugins/wavpack/wavpack.c2
-rw-r--r--streamer.c16
12 files changed, 57 insertions, 29 deletions
diff --git a/deadbeef.h b/deadbeef.h
index ca63cda1..b1fb074c 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -279,7 +279,8 @@ typedef struct {
int (*cond_broadcast) (uintptr_t cond);
// playlist access
DB_playItem_t * (*pl_item_alloc) (void);
- void (*pl_item_free) (DB_playItem_t *it);
+ void (*pl_item_ref) (DB_playItem_t *it);
+ void (*pl_item_unref) (DB_playItem_t *it);
void (*pl_item_copy) (DB_playItem_t *out, DB_playItem_t *in);
int (*pl_add_file) (const char *fname, int (*cb)(DB_playItem_t *it, void *data), void *user_data);
int (*pl_add_dir) (const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data);
diff --git a/playlist.c b/playlist.c
index c458559a..c370611e 100644
--- a/playlist.c
+++ b/playlist.c
@@ -64,6 +64,9 @@ static int playlists_count = 0;
static playlist_t *playlists_head = NULL;
static playlist_t *playlist = NULL; // current playlist
+static void
+pl_item_free (playItem_t *it);
+
int
plt_get_count (void) {
return playlists_count;
@@ -320,8 +323,7 @@ pl_process_cue_track (playItem_t *after, const char *fname, playItem_t **prev, c
*prev = NULL;
return after;
}
- playItem_t *it = malloc (sizeof (playItem_t));
- memset (it, 0, sizeof (playItem_t));
+ playItem_t *it = pl_item_alloc ();
it->decoder_id = plug_get_decoder_id (decoder_id);
it->fname = strdup (fname);
it->tracknum = atoi (track);
@@ -862,8 +864,8 @@ pl_remove (playItem_t *it) {
pl_totaltime = 0;
}
}
- pl_item_free (it);
- free (it);
+ pl_item_unref (it);
+ //free (it);
return 0;
}
@@ -972,6 +974,7 @@ pl_item_copy (playItem_t *out, playItem_t *it) {
out->prev[PL_MAIN] = it->prev[PL_MAIN];
out->next[PL_SEARCH] = it->next[PL_SEARCH];
out->prev[PL_SEARCH] = it->prev[PL_SEARCH];
+ out->_refc = 1;
// copy metainfo
metaInfo_t *prev = NULL;
metaInfo_t *meta = it->meta;
@@ -997,10 +1000,16 @@ pl_item_alloc (void) {
memset (it, 0, sizeof (playItem_t));
it->replaygain_album_peak = 1;
it->replaygain_track_peak = 1;
+ it->_refc = 1;
return it;
}
void
+pl_item_ref (playItem_t *it) {
+ it->_refc++;
+}
+
+static void
pl_item_free (playItem_t *it) {
if (it) {
if (it->fname) {
@@ -1017,6 +1026,17 @@ pl_item_free (playItem_t *it) {
}
void
+pl_item_unref (playItem_t *it) {
+ it->_refc--;
+ if (it->_refc < 0) {
+ fprintf (stderr, "playlist: bad refcount on item %p\n", it);
+ }
+ if (it->_refc <= 0) {
+ pl_item_free (it);
+ }
+}
+
+void
pl_add_meta (playItem_t *it, const char *key, const char *value) {
// check if it's already set
metaInfo_t *m = it->meta;
@@ -1263,11 +1283,10 @@ pl_load (const char *fname) {
goto load_fail;
}
for (uint32_t i = 0; i < cnt; i++) {
- it = malloc (sizeof (playItem_t));
+ it = pl_item_alloc ();
if (!it) {
goto load_fail;
}
- memset (it, 0, sizeof (playItem_t));
uint16_t l;
// fname
if (fread (&l, 1, 2, fp) != 2) {
@@ -1425,7 +1444,7 @@ load_fail:
fprintf (stderr, "playlist load fail (%s)!\n", fname);
fclose (fp);
if (it) {
- pl_item_free (it);
+ pl_item_unref (it);
}
pl_free ();
return -1;
diff --git a/playlist.h b/playlist.h
index 0fb5ad84..0d37e1b4 100644
--- a/playlist.h
+++ b/playlist.h
@@ -46,6 +46,7 @@ typedef struct playItem_s {
float replaygain_track_peak;
// private area, must not be visible to plugins
float _duration; // in seconds
+ int _refc;
struct playItem_s *next[PL_MAX_ITERATORS]; // next item in linked list
struct playItem_s *prev[PL_MAX_ITERATORS]; // prev item in linked list
struct metaInfo_s *meta; // linked list storing metainfo
@@ -107,7 +108,13 @@ playItem_t *
pl_item_alloc (void);
void
-pl_item_free (playItem_t *it);
+pl_item_ref (playItem_t *it);
+
+void
+pl_item_unref (playItem_t *it);
+
+//void
+//pl_item_free (playItem_t *it);
void
pl_item_copy (playItem_t *out, playItem_t *it);
diff --git a/plugins.c b/plugins.c
index b9732f73..230248e7 100644
--- a/plugins.c
+++ b/plugins.c
@@ -103,7 +103,8 @@ static DB_functions_t deadbeef_api = {
.cond_broadcast = cond_broadcast,
// playlist access
.pl_item_alloc = (DB_playItem_t* (*)(void))pl_item_alloc,
- .pl_item_free = (void (*)(DB_playItem_t *))pl_item_free,
+ .pl_item_ref = (void (*)(DB_playItem_t *))pl_item_ref,
+ .pl_item_unref = (void (*)(DB_playItem_t *))pl_item_unref,
.pl_item_copy = (void (*)(DB_playItem_t *, DB_playItem_t *))pl_item_copy,
.pl_add_file = (int (*) (const char *, int (*cb)(DB_playItem_t *it, void *data), void *))pl_add_file,
.pl_add_dir = (int (*) (const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data))pl_add_dir,
diff --git a/plugins/ffap/ffap.c b/plugins/ffap/ffap.c
index 0a4e3276..4319fd5f 100644
--- a/plugins/ffap/ffap.c
+++ b/plugins/ffap/ffap.c
@@ -1721,7 +1721,7 @@ ffap_insert (DB_playItem_t *after, const char *fname) {
DB_playItem_t *cue = deadbeef->pl_insert_cue (after, it, ape_ctx.totalsamples, ape_ctx.samplerate);
if (cue) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
return cue;
}
@@ -1730,7 +1730,7 @@ ffap_insert (DB_playItem_t *after, const char *fname) {
if (cuesheet) {
cue = deadbeef->pl_insert_cue_from_buffer (after, it, cuesheet, strlen (cuesheet), ape_ctx.totalsamples, ape_ctx.samplerate);
if (cue) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
return cue;
}
}
diff --git a/plugins/ffmpeg/ffmpeg.c b/plugins/ffmpeg/ffmpeg.c
index 0aa91527..ed690edf 100644
--- a/plugins/ffmpeg/ffmpeg.c
+++ b/plugins/ffmpeg/ffmpeg.c
@@ -500,7 +500,7 @@ ffmpeg_insert (DB_playItem_t *after, const char *fname) {
// external cuesheet
DB_playItem_t *cue = deadbeef->pl_insert_cue (after, it, totalsamples, samplerate);
if (cue) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
return cue;
}
// now the track is ready, insert into playlist
diff --git a/plugins/flac/flac.c b/plugins/flac/flac.c
index f621b50f..dbb355d3 100644
--- a/plugins/flac/flac.c
+++ b/plugins/flac/flac.c
@@ -631,7 +631,7 @@ cflac_insert (DB_playItem_t *after, const char *fname) {
if (cuesheet) {
DB_playItem_t *last = deadbeef->pl_insert_cue_from_buffer (after, it, cuesheet, strlen (cuesheet), info.totalsamples, info.info.samplerate);
if (last) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
return last;
}
}
@@ -659,7 +659,7 @@ cflac_insert (DB_playItem_t *after, const char *fname) {
return after;
cflac_insert_fail:
if (it) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
}
if (decoder) {
FLAC__stream_decoder_delete(decoder);
diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c
index 3a8de2c0..d441a8c2 100644
--- a/plugins/lastfm/lastfm.c
+++ b/plugins/lastfm/lastfm.c
@@ -618,7 +618,7 @@ lfm_send_submissions (void) {
deadbeef->mutex_lock (lfm_mutex);
for (i = 0; i < LFM_SUBMISSION_QUEUE_SIZE; i++) {
if (lfm_subm_queue[i]) {
- deadbeef->pl_item_free (lfm_subm_queue[i]);
+ deadbeef->pl_item_unref (lfm_subm_queue[i]);
lfm_subm_queue[i] = NULL;
}
}
@@ -633,7 +633,7 @@ lfm_send_submissions (void) {
deadbeef->mutex_lock (lfm_mutex);
for (i = 0; i < LFM_SUBMISSION_QUEUE_SIZE; i++) {
if (lfm_subm_queue[i]) {
- deadbeef->pl_item_free (lfm_subm_queue[i]);
+ deadbeef->pl_item_unref (lfm_subm_queue[i]);
lfm_subm_queue[i] = NULL;
}
}
diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c
index b954d39e..d2355dc5 100644
--- a/plugins/mpgmad/mpgmad.c
+++ b/plugins/mpgmad/mpgmad.c
@@ -1059,7 +1059,7 @@ cmp3_insert (DB_playItem_t *after, const char *fname) {
// FIXME! bad numsamples passed to cue
DB_playItem_t *cue_after = deadbeef->pl_insert_cue (after, it, buffer.duration*buffer.samplerate, buffer.samplerate);
if (cue_after) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
return cue_after;
}
diff --git a/plugins/vorbis/vorbis.c b/plugins/vorbis/vorbis.c
index 3e7ddefb..6a69b57b 100644
--- a/plugins/vorbis/vorbis.c
+++ b/plugins/vorbis/vorbis.c
@@ -394,7 +394,7 @@ cvorbis_insert (DB_playItem_t *after, const char *fname) {
DB_playItem_t *cue = deadbeef->pl_insert_cue (after, it, totalsamples, samplerate);
if (cue) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
return cue;
}
@@ -403,7 +403,7 @@ cvorbis_insert (DB_playItem_t *after, const char *fname) {
if (cuesheet) {
cue = deadbeef->pl_insert_cue_from_buffer (after, it, cuesheet, strlen (cuesheet), totalsamples, samplerate);
if (cue) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
return cue;
}
}
diff --git a/plugins/wavpack/wavpack.c b/plugins/wavpack/wavpack.c
index 7c2aa350..19dcf3f3 100644
--- a/plugins/wavpack/wavpack.c
+++ b/plugins/wavpack/wavpack.c
@@ -264,7 +264,7 @@ wv_insert (DB_playItem_t *after, const char *fname) {
if (cuesheet) {
DB_playItem_t *last = deadbeef->pl_insert_cue_from_buffer (after, it, cuesheet, strlen (cuesheet), totalsamples, samplerate);
if (last) {
- deadbeef->pl_item_free (it);
+ deadbeef->pl_item_unref (it);
return last;
}
}
diff --git a/streamer.c b/streamer.c
index 46426f9a..5d1c00b2 100644
--- a/streamer.c
+++ b/streamer.c
@@ -148,7 +148,7 @@ streamer_set_current (playItem_t *it) {
if(str_current_decoder) {
str_current_decoder->plugin->free (str_current_decoder);
str_current_decoder = NULL;
- pl_item_free (&str_streaming_song);
+ pl_item_unref (&str_streaming_song);
}
orig_streaming_song = it;
if (!it) {
@@ -285,8 +285,8 @@ streamer_thread (void *ctx) {
if (!try) { // track is not in playlist
trace ("track #%d is not in playlist; stopping playback\n", sng);
p_stop ();
- pl_item_free (&str_playing_song);
- pl_item_free (&str_streaming_song);
+ pl_item_unref (&str_playing_song);
+ pl_item_unref (&str_streaming_song);
orig_playing_song = NULL;
orig_streaming_song = NULL;
messagepump_push (M_SONGCHANGED, 0, -1, -1);
@@ -332,7 +332,7 @@ streamer_thread (void *ctx) {
plug_trigger_event (DB_EV_SONGFINISHED, 0);
}
streamer_set_current (NULL);
- pl_item_free (&str_playing_song);
+ pl_item_unref (&str_playing_song);
orig_playing_song = NULL;
messagepump_push (M_SONGCHANGED, 0, from, -1);
continue;
@@ -363,7 +363,7 @@ streamer_thread (void *ctx) {
plug_trigger_event (DB_EV_SONGFINISHED, 0);
}
// free old copy of playing
- pl_item_free (&str_playing_song);
+ pl_item_unref (&str_playing_song);
// copy streaming into playing
pl_item_copy (&str_playing_song, &str_streaming_song);
last_bitrate = -1;
@@ -397,7 +397,7 @@ streamer_thread (void *ctx) {
if(str_current_decoder) {
str_current_decoder->plugin->free (str_current_decoder);
str_current_decoder = NULL;
- pl_item_free (&str_streaming_song);
+ pl_item_unref (&str_streaming_song);
}
orig_streaming_song = orig_playing_song;
pl_item_copy (&str_streaming_song, orig_streaming_song);
@@ -484,8 +484,8 @@ streamer_thread (void *ctx) {
str_current_decoder->plugin->free (str_current_decoder);
str_current_decoder = NULL;
}
- pl_item_free (&str_streaming_song);
- pl_item_free (&str_playing_song);
+ pl_item_unref (&str_streaming_song);
+ pl_item_unref (&str_playing_song);
if (src) {
src_delete (src);
src = NULL;