aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* playlist: PlaylistInfo() does not call commandError()Max Kellermann2008-09-091-4/+1
| | | | | | Continuing the effort of removing protocol specific calls from the core libraries: let the command.c code call commandError() based on PlaylistInfo's return value.
* playlist: don't pass "fd" to storedPlaylist.c functionsMax Kellermann2008-09-091-31/+17
| | | | | Return an "enum playlist_result" value instead of calling commandError() in storedPlaylist.c.
* playlist: don't pass "fd" to playlist.c functionsMax Kellermann2008-09-091-128/+88
| | | | | | The playlist library shouldn't talk to the client if possible. Introduce the "enum playlist_result" type which the caller (i.e. command.c) may use to generate an error message.
* playlist: showPlaylist() and shufflePlaylist() cannot failMax Kellermann2008-09-091-6/+2
| | | | Make them both return void.
* playlist: moved "repeat" and "random" value checks to command.cMax Kellermann2008-09-091-20/+6
| | | | | | | | Client's input values should be validated by the command implementation, and the core libraries shouldn't talk to the client directly if possible. Thus, setPlaylistRepeatStatus() and setPlaylistRandomStatus() don't get the file descriptor, and cannot fail (return void).
* playlist: added is_valid_playlist_name()Max Kellermann2008-09-091-3/+8
| | | | | | | | The function valid_playlist_name() checks the name, but it insists on reporting an eventual error to the client. The new function is_valid_playlist_name() is more generic: it just returns a boolean, and does not care what the caller will use it for. The old function valid_playlist_name() will be removed later.
* dbUtils, playlist, directory: pass constant pointersMax Kellermann2008-09-091-7/+7
| | | | The usual bunch of const pointer conversions.
* playlist: re-randomize when explicitly playing a new songEric Wong2008-09-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | When random is enabled and a user explicitly specifies a certain song on the playlist should be played; we need to re-randomize the internal ordering. To reproduce this, assuming a four song playlist: play <song_a> next => <song_b> next => <song_c> next => <song_d> play <song_a> next => <song_b> next => <song_c> next => <song_d> ... That is, the "next" command restarts song_{b,c,d} the second time "play" starts playing song_a. Thus, the second time "play" is called, the ordering of song_{b,c,d} needs to be reshuffled. Reported-by: Qball
* tag: renamed functions, no CamelCaseMax Kellermann2008-09-021-3/+3
|
* tag: renamed MpdTag and MpdTagItem to struct mpd_tag, struct tag_itemMax Kellermann2008-09-021-2/+2
| | | | | Getting rid of CamelCase; not having typedefs also allows us to forward-declare the structures.
* playlist: fix shuffle/random distributionEric Wong2008-09-011-6/+19
| | | | | | | | | | Previously we were using a naive randomization algorithm that could shuffle already shuffled songs. Now we attempt to correctly[1] implement the Fisher-Yates shuffle. [1] Note: I absolutely suck at basic arithmetic, so there could be off-by-one errors in here, too. I've added assertions in swapSongs and swapOrder functions to more quickly detect them.
* playlist: eliminate unused fd parametersMax Kellermann2008-08-311-22/+18
| | | | | Again, remove file descriptor parameters, which are not actually used. These functions can also be converted to return void.
* enable -Wpointer-arith, -Wstrict-prototypesMax Kellermann2008-08-301-1/+1
| | | | | | Also enable -Wunused-parameter - this forces us to add the gcc "unused" attribute to a lot of parameters (mostly library callback functions), but it's worth it during code refactorizations.
* playlist: fix deleting the last song in a playlistEric Wong2008-08-271-1/+2
| | | | | | | | | unK reported a bug in which explicitly calling "delete" on each song would cause mpd to lock up. This is actually triggered when the only song on the mpd playlist is deleted. Additionally, add an extra assertion to ensure we play a valid, non-NULL song in play_order_num().
* Reimplement dynamic metadata handlingEric Wong2008-08-261-19/+24
| | | | | | | | | | | | This has been tested for both playback of streams and outputting to streams, and seems to work fine with minimal locking. This reuses the sequence number infrastructure in OutputBuffer for synchronizing metadata payloads; so (IMNSHO) should be much more understandable than various flags being set here and there.. It could still use some cleanup and much testing, but synchronization issues should be minimal.
* playlist: fix "currentsong" after song deletionEric Wong2008-08-251-0/+2
| | | | | | | | | | When deleting previous songs, we forgot to update the playlist.queue value, causing syncPlaylistWithQueue to trigger a false sync and screw with the playlist.current pointer; causing the currentsong command to return an incorrect song. Thanks to unK to reporting this bug!
* playlist: fix "currentsong" after song movementEric Wong2008-08-251-1/+4
| | | | | | | | When moving songs around, we forgot to update the playlist.queue value, causing syncPlaylistWithQueue to trigger a false sync and screw with the playlist.current pointer; causing the currentsong command to return an incorrect song.
* playlist: queue songs after adding themEric Wong2008-08-231-0/+6
| | | | | | | This fixes the case where we wouldn't start playing a newly added song if we're near the end of the playlist and done decoding the last song (but still playing from the buffer).
* change queueNextSongInPlaylist assertion to checkEric Wong2008-08-231-1/+2
| | | | | | | There are still some places where we try to call this function without the playlist being stopped. It's really harmless, to call it and just break out immediately, so change the assertion.
* Remove ob_wait_sync and cleanup triggering in playlistEric Wong2008-08-191-44/+28
| | | | | | | | ob_wait_sync was a gross hack anyways. We are one step closer to being able to trigger actions in our worker threads asynchronously. Just need to make input (file opening) in decoder happen _after_ our decoder returns an ACK.
* core rewrite (decode,player,outputBuffer,playlist)Eric Wong2008-08-161-261/+281
| | | | | | | | | | | | | This is a huge refactoring of the core mpd process. The queueing/buffering mechanism is heavily reworked. The player.c code has been merged into outputBuffer (the actual ring buffering logic is handled by ringbuf.c); and decode.c actually handles decoding stuff. The end result is several hundreds of lines shorter, even though we still have a lot of DEBUG statements left in there for tracing and a lot of assertions, too.
* clean up CPP includesMax Kellermann2008-04-121-1/+2
| | | | | | | | | Try to only include headers which are really needed. We should particularly check all "headers including other headers". The long-term goal is to have a manageable, small API for plugins (decoders, output) without so many mpd internals cluttering the namespace. git-svn-id: https://svn.musicpd.org/mpd/trunk@7319 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* added clearPlayerQueueLocked()Max Kellermann2008-04-121-43/+24
| | | | | | | since clearPlayerQueue() is always called within lockPlaylistInteraction() / unlockPlaylistInteraction(), it simplifies the code to add another function which calls these three functions. git-svn-id: https://svn.musicpd.org/mpd/trunk@7253 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* fix strtok() related segmentation faultMax Kellermann2008-03-261-1/+4
| | | | | | strtok() may return NULL if the input is an empty string. The playlist parser did not check for that. git-svn-id: https://svn.musicpd.org/mpd/trunk@7200 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* eliminated duplicate initializationMax Kellermann2008-03-261-2/+2
| | | | | | | Local variables which are never read before the first assignment don't need initialization. Saves a few bytes of text. Also don't reset variables which are never read until function return. git-svn-id: https://svn.musicpd.org/mpd/trunk@7199 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* fix "unreachable code" warningMax Kellermann2008-03-261-6/+0
| | | | | | There is unreachable code at several positions, e.g. after an #if/#end, or after an endless loop. Remove that. git-svn-id: https://svn.musicpd.org/mpd/trunk@7197 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* check the result of fopen() in all code pathsMax Kellermann2008-03-261-0/+5
| | | | | | | The while() loop only checks for interrupted system calls (which woudl never happen if the signal mask were set up properly), but nobody checks if the fopen() actually succeeds. git-svn-id: https://svn.musicpd.org/mpd/trunk@7195 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Revert the queue implementation and commandsEric Wong2008-01-261-173/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's too ugly and broken (both technically and usability-wise) to be worth supporting in any stable release. In one sentence: The queue is a very crippled version of the playlist that takes precedence over the normal playlist. How is it crippled? * The "queueid" command only allows the queuing of songs ALREADY IN THE PLAYLIST! This promotes having the entire mpd database of songs in the playlist, which is a stupid practice to begin with. * It doesn't allow for meaningful rearranging and movement of songs within the queue. To move a song, you'd need to dequeue and requeue it (and other songs on the list). Why? The playlist already allows _all_ these features and shows everything a client needs to know about the ordering of songs in a _single_ command! * Random was a stupid idea to begin with and unfortunately we're stuck supporting it since we've always had it. Users should learn to use "shuffle" instead and not look at their playlists. Implementing queue because we have the problem of random is just a bandage fix and digging ourselves a new hole. This protocol addition was never in a stable release of mpd, so reverting it will only break things for people following trunk; which I'm not too worried about. I am however worried about long-term support of this misfeature, so I'm removing it. Additionally, there are other points: * It's trivially DoS-able: (while true; do echo queueid $song_id; done) | nc $MPD_HOST $MPD_PORT The above commands would cause the queue to become infinitely expanding, taking up all available memory in the system. The mpd playlist was implemented as an array with a fixed (but configurable) size limit for this reason. * It's not backwards-compatible. All clients would require upgrades (and additional complexity) to even know what the next song in the playlist is. mpd is a shared architecture, and we should not violate the principle of least astonishment here. This removes the following commands: queueid, dequeue, queueinfo Additionally, the status field of "playlistqueue: " is removed from the status command. While this DoS is trivial to fix, the design is simply too broken to ever support in a real release. The overloading of the "addid" command and the allowing of negative numbers to be used as offsets is far more flexible. This improved "addid" is completely backwards-compatible with all clients, and does not require clients to have UI changes or run additional commands to display the queue. git-svn-id: https://svn.musicpd.org/mpd/trunk@7155 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* storedPlaylist: prevent potential DoS from stored playlist commandsEric Wong2008-01-261-1/+1
| | | | | | | | | | | | | | | | | | | | While mpd has always protected against the infinite expansion of the main playlist by limiting its size in memory, however the new storedPlaylist code has never checked for this limit. Malicious (or clumsy) users could repeatedly append songs to stored playlists, causing files to grow increasingly large on disk. Attempting to load extremely large files into memory will require mpd to slurp that all into memory, and ultimately the file would be unusable by mpd because of the configurable playlist size limit. Now we limit stored playlists to the max_playlist_length configuration variable set by the user (default is 16384). We will refuse to append to playlist files if they hit that limit; and also refuse to load more than the specified amount of songs into memory. git-svn-id: https://svn.musicpd.org/mpd/trunk@7154 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* playlist: don't allow no-op/senseless movement of songsEric Wong2008-01-261-8/+14
| | | | | | | | | | This disables moving the bonkered moving of the current song to a (negative) offset of itself (introduced in the last commit). This also short circuits no-op moves when (from == to) and avoid needless increasing of the playlist version and causes clients to issue pointless no-op plchanges commands. git-svn-id: https://svn.musicpd.org/mpd/trunk@7153 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* playlist: allow move to specify offset from current songEric Wong2008-01-261-1/+10
| | | | | | | | | | | | | | | | If (and only if) there is a current song in the playlist, (player could be stopped), allow the move destination argument to be specified as a negative number. This means moving any song (besides the current one) to the -1 position will allow it to be moved to the next song in the playlist. Moving any song to position -2 will move it to the song after the next, and so forth. Moving a song to -playlist.length will move it to the song _before_ the current song on the playlist; so this will work for repeating playlists, too. git-svn-id: https://svn.musicpd.org/mpd/trunk@7152 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* addToPlaylist/addSongToPlaylist: printId argument changed to added_idEric Wong2008-01-261-8/+9
| | | | | | | | | | | | Instead of printing out the Id from playlist.c, instead set the integer that added_id poitns to if added_id is non-NULL. This makes the API cleaner and will allow us to use additional commands to manipulate the newly-added song_id. Callers (handleAddId) that relied on printId to print it to the given fd have now been modified to print the ID at a higher-level; making playlist.c less-dependent on protocol details. git-svn-id: https://svn.musicpd.org/mpd/trunk@7149 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* fixed -Wshadow warningsMax Kellermann2008-01-261-9/+10
| | | | | Signed-off-by: Eric Wong <normalperson@yhbt.net> git-svn-id: https://svn.musicpd.org/mpd/trunk@7143 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Cleanup #includes of standard system headers and put them in one placeEric Wong2008-01-031-8/+1
| | | | | | | | | | | | | This will make refactoring features easier, especially now that pthreads support and larger refactorings are on the horizon. Hopefully, this will make porting to other platforms (even non-UNIX-like ones for masochists) easier, too. os_compat.h will house all the #includes for system headers considered to be the "core" of MPD. Headers for optional features will be left to individual source files. git-svn-id: https://svn.musicpd.org/mpd/trunk@7130 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* storedPlaylist: remove the needless StoredPlaylist struct and just use ListEric Wong2008-01-011-8/+8
| | | | | | | | | | | Abstractions should reduce the amount of code and make things easier to follow. The StoredPlaylist struct did not do that, so get rid of it and just use our standard linked list implementation instead. diffstat agrees with me that the abstraction is pointless: 3 files changed, 60 insertions(+), 90 deletions(-) git-svn-id: https://svn.musicpd.org/mpd/trunk@7120 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* storedPlaylist: cleanup API and avoid needless heap allocations + error checksEric Wong2008-01-011-8/+10
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@7119 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* playlist: cleanup pathname generation for the "rm" command, tooEric Wong2008-01-011-15/+5
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@7117 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* playlist: avoid the use of newStoredPlaylist for saving active playlistsEric Wong2008-01-011-6/+52
| | | | | | It was a nice way to double the memory needed to write the playlist to a file. git-svn-id: https://svn.musicpd.org/mpd/trunk@7116 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Merge branches/ew r7104Eric Wong2007-12-281-13/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | thread-safety work in preparation for rewrite to use pthreads Expect no regressions against trunk (r7078), possibly minor performance improvements in update (due to fewer heap allocations), but increased stack usage. Applied the following patches: * maxpath_str for reentrancy (temporary fix, reverted) * path: start working on thread-safe variants of these methods * Re-entrancy work on path/character-set conversions * directory.c: exploreDirectory() use reentrant functions here * directory/update: more use of reentrant functions + cleanups * string_toupper: a strdup-less version of strDupToUpper * get_song_url: a static-variable-free version of getSongUrl() * Use reentrant/thread-safe get_song_url everywhere * replace rmp2amp with the reentrant version, rmp2amp_r * Get rid of the non-reentrant/non-thread-safe rpp2app, too. * buffer2array: assert strdup() returns a usable value in unit tests * replace utf8ToFsCharset and fsCharsetToUtf8 with thread-safe variants * fix storing playlists w/o absolute paths * parent_path(), a reentrant version of parentPath() * parentPath => parent_path for reentrancy and thread-safety * allow "make test" to automatically run embedded unit tests * remove convStrDup() and maxpath_str() * use MPD_PATH_MAX everywhere instead of MAXPATHLEN * path: get rid of appendSlash, pfx_path and just use pfx_dir * get_song_url: fix the ability to play songs in the top-level music_directory git-svn-id: https://svn.musicpd.org/mpd/trunk@7106 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* If clearing stored playlist fails, don't return error + OK. but only the error.Qball Cow2007-12-271-2/+1
| | | | | | this was caused by always having the handleStoredPlaylist function return 0. git-svn-id: https://svn.musicpd.org/mpd/trunk@7105 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Playlist queue patch (http://musicpd.org/mantis/view.php?id=1478) version 11.Qball Cow2007-09-261-1/+172
| | | | | | | | | | | | | This adds the following commands: * queueid <id> Add song <id> to the queue. * dequeue <pos> Remove song from <pos> from the queue * queueinfo List the queue To the statusfield it adds the following entry: playlistqueue: <uid> UID can be used by clients to track changes in the playlist queue. git-svn-id: https://svn.musicpd.org/mpd/trunk@6927 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* conf: improved boolean config parameter handling from -keEric Wong2007-09-051-5/+5
| | | | | | the force flag will issue FATAL() if an invalid value is specified git-svn-id: https://svn.musicpd.org/mpd/trunk@6857 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Don't kill the player process (and effectively the decode process) whenJ. Alexander Treuman2007-06-041-2/+2
| | | | | | completely stopped. Instead, send them SIGSTOP to pause the process until they're needed again. Then send them SIGCONT instead of re-spawning them. git-svn-id: https://svn.musicpd.org/mpd/trunk@6485 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Making some bool options more consistent.J. Alexander Treuman2007-06-031-2/+4
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@6468 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Tell the player process (and thus also the decode process) to quit whenJ. Alexander Treuman2007-06-011-3/+2
| | | | | | | | | | playback is stopped completely. This means the player process will no longer have to wake up 100 times per second to see if it's been told to start playing (the main process will just spawn a new player process when it needs to). On the downside, this means an extra pair of forks() and the re-initializing of the player and decode processes each time playback is restarted. git-svn-id: https://svn.musicpd.org/mpd/trunk@6446 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Minor formatting cleanups.J. Alexander Treuman2007-06-011-2/+0
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@6444 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Changing all calls to ERROR() followed by exit(EXIT_FAILURE) with a singleJ. Alexander Treuman2007-05-261-2/+1
| | | | | call to FATAL(). git-svn-id: https://svn.musicpd.org/mpd/trunk@6276 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Cleaning up addToStoredPlaylist. Now we call freeJustSong if adding a URL.J. Alexander Treuman2007-05-261-9/+18
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@6269 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Make sure StoredPlaylists always contain UTF-8 paths that are eitherJ. Alexander Treuman2007-05-261-3/+1
| | | | | | | | | | | | | | | | | | | | | | relative paths in the DB or URLs. The main functional difference is that playlistmove and playlistdelete will rewrite playlists in the correct encoding and remove invalid lines instead of potentially modifying them. The specific changes are: appendSongToStoredPlaylist: * Don't convert to FS charset * Don't prepend music_directory if saving absolute paths writeStoredPlaylistToPath: * Convert to FS charset * Prepend music_directory if saving absolute paths loadStoredPlaylist: * Make sure each line is either in the DB or a URL loadPlaylist: * Don't bother checking paths, since it's done in loadStoredPlaylist now git-svn-id: https://svn.musicpd.org/mpd/trunk@6266 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Committing pat's rewrite of the stored playlist code. This also adds twoJ. Alexander Treuman2007-05-161-277/+56
| | | | | new commands: playlistmove and playlistdelete. git-svn-id: https://svn.musicpd.org/mpd/trunk@6116 09075e82-0dd4-0310-85a5-a0d7c8717e4f