aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2008-10-03playlist: small lines of code reductionEric Wong1-96/+47
Hopefully this makes the code feel less claustrophobic...
2008-10-02Revert "Start using song pointers in core data structures"Eric Wong1-2/+6
This actually opened us up to making lock dependencies more difficult than they needed to be now that we have threaded updates. We would always use the memory anyways, just in the stack instead of bss.
2008-09-29Switch to C99 types (retaining compat with old compilers)Eric Wong1-6/+6
Seeing the "mpd_" prefix _everywhere_ is mind-numbing as the mind needs to retrain itself to skip over the first 4 tokens of a type to get to its meaning. So avoid having extra characters on my terminal to make it easier to follow code at 2:30 am in the morning. Please report any new issues you may come across on Free toolchains. I realize how difficult it can be to build/maintain cross-compiling toolchains and I have no intention of forcing people to upgrade their toolchains to build mpd. Tested with gcc 2.95.4 and and gcc 4.3.1 on x86-32.
2008-09-28playlist: deleteASongFromPlaylist takes a const Song *Eric Wong1-1/+1
We don't change the song pointer there, either.
2008-09-28playlist: fix currentsong info after swapping songsEric Wong1-0/+4
We forgot to update the playlist.queued marker if playlist.current changed. Additionally, if the queue cleared in any other mode, attempt to requeue (as it's a harmless no-op otherwise). Thanks to stonecrest for the bug report.
2008-09-28playlist: reset after we've hit the endEric Wong1-0/+6
If repeat is off, we reset (and reshuffle in random mode) the playlist.
2008-09-28advance to the next song on decoder errorsEric Wong1-1/+5
Fix this regression introduced in the core rewrite so that we now skip to the next song when we encounter an error with the song we tried to decode.
2008-09-20start using prefixcmp()Eric Wong1-23/+8
LOC reduction and less noise makes things easier for tired old folks to follow.
2008-09-18Move away from fprintf() when writing DB/state_fileEric Wong1-17/+17
I have serious trust issues when using stdio to write to the FS. So it's best to clean this code out so I can start figuring out what's wrong with Rasi's box not updating... None of these writes take place in a performance-critical setting anyways...
2008-09-09playlist: PlaylistInfo() does not call commandError()Max Kellermann1-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.
2008-09-09playlist: don't pass "fd" to storedPlaylist.c functionsMax Kellermann1-31/+17
Return an "enum playlist_result" value instead of calling commandError() in storedPlaylist.c.
2008-09-09playlist: don't pass "fd" to playlist.c functionsMax Kellermann1-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.
2008-09-09playlist: showPlaylist() and shufflePlaylist() cannot failMax Kellermann1-6/+2
Make them both return void.
2008-09-09playlist: moved "repeat" and "random" value checks to command.cMax Kellermann1-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).
2008-09-09playlist: added is_valid_playlist_name()Max Kellermann1-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.
2008-09-09dbUtils, playlist, directory: pass constant pointersMax Kellermann1-7/+7
The usual bunch of const pointer conversions.
2008-09-07playlist: re-randomize when explicitly playing a new songEric Wong1-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
2008-09-02tag: renamed functions, no CamelCaseMax Kellermann1-3/+3
2008-09-02tag: renamed MpdTag and MpdTagItem to struct mpd_tag, struct tag_itemMax Kellermann1-2/+2
Getting rid of CamelCase; not having typedefs also allows us to forward-declare the structures.
2008-09-01playlist: fix shuffle/random distributionEric Wong1-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.
2008-08-31playlist: eliminate unused fd parametersMax Kellermann1-22/+18
Again, remove file descriptor parameters, which are not actually used. These functions can also be converted to return void.
2008-08-30enable -Wpointer-arith, -Wstrict-prototypesMax Kellermann1-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.
2008-08-27playlist: fix deleting the last song in a playlistEric Wong1-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().
2008-08-26Reimplement dynamic metadata handlingEric Wong1-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.
2008-08-25playlist: fix "currentsong" after song deletionEric Wong1-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!
2008-08-25playlist: fix "currentsong" after song movementEric Wong1-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.
2008-08-23playlist: queue songs after adding themEric Wong1-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).
2008-08-23change queueNextSongInPlaylist assertion to checkEric Wong1-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.
2008-08-19Remove ob_wait_sync and cleanup triggering in playlistEric Wong1-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.
2008-08-16core rewrite (decode,player,outputBuffer,playlist)Eric Wong1-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.
2008-04-12clean up CPP includesMax Kellermann1-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
2008-04-12added clearPlayerQueueLocked()Max Kellermann1-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
2008-03-26fix strtok() related segmentation faultMax Kellermann1-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
2008-03-26eliminated duplicate initializationMax Kellermann1-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
2008-03-26fix "unreachable code" warningMax Kellermann1-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
2008-03-26check the result of fopen() in all code pathsMax Kellermann1-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
2008-01-26Revert the queue implementation and commandsEric Wong1-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
2008-01-26storedPlaylist: prevent potential DoS from stored playlist commandsEric Wong1-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
2008-01-26playlist: don't allow no-op/senseless movement of songsEric Wong1-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
2008-01-26playlist: allow move to specify offset from current songEric Wong1-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
2008-01-26addToPlaylist/addSongToPlaylist: printId argument changed to added_idEric Wong1-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
2008-01-26fixed -Wshadow warningsMax Kellermann1-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
2008-01-03Cleanup #includes of standard system headers and put them in one placeEric Wong1-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
2008-01-01storedPlaylist: remove the needless StoredPlaylist struct and just use ListEric Wong1-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
2008-01-01storedPlaylist: cleanup API and avoid needless heap allocations + error checksEric Wong1-8/+10
git-svn-id: https://svn.musicpd.org/mpd/trunk@7119 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01playlist: cleanup pathname generation for the "rm" command, tooEric Wong1-15/+5
git-svn-id: https://svn.musicpd.org/mpd/trunk@7117 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01playlist: avoid the use of newStoredPlaylist for saving active playlistsEric Wong1-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
2007-12-28Merge branches/ew r7104Eric Wong1-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
2007-12-27If clearing stored playlist fails, don't return error + OK. but only the error.Qball Cow1-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
2007-09-26Playlist queue patch (http://musicpd.org/mantis/view.php?id=1478) version 11.Qball Cow1-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