From c0fbab7a7cfcca8c1fa6ac5ea532924b35938923 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 9 Sep 2014 00:38:38 +0200 Subject: player: deal with some corner cases with playlist navigation The purpose is making accessing the current playlist entry saner when commands are executed during initialization, termination, or after playlist navigation commands. For example, the "playlist_remove current" command will invalidate playlist->current - but some things still access the playlist entry even on uninit. Until now, checking stop_play implicitly took care of it, so it worked, but it was still messy. Introduce the mpctx->playing field, which points to the current playlist entry, even if the entry was removed and/or the playlist's current entry was moved (e.g. due to playlist navigation). --- common/playlist.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'common/playlist.c') diff --git a/common/playlist.c b/common/playlist.c index 46ae36d643..857f5cb030 100644 --- a/common/playlist.c +++ b/common/playlist.c @@ -106,10 +106,18 @@ static void playlist_unlink(struct playlist *pl, struct playlist_entry *entry) entry->pl = NULL; } +void playlist_entry_unref(struct playlist_entry *e) +{ + e->reserved--; + if (e->reserved < 0) + talloc_free(e); +} + void playlist_remove(struct playlist *pl, struct playlist_entry *entry) { playlist_unlink(pl, entry); - talloc_free(entry); + entry->removed = true; + playlist_entry_unref(entry); } void playlist_clear(struct playlist *pl) -- cgit v1.2.3