aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* database: renamed functions, "db_" prefix and no CamelCaseMax Kellermann2008-10-111-3/+3
| | | | Yet another CamelCase removal patch.
* directory: moved code to database.cMax Kellermann2008-10-111-1/+1
| | | | | | Taming the directory.c monster, part II: move the database management stuff to database. directory.c should only contain code which works on directory objects.
* song: removed CamelCaseMax Kellermann2008-10-111-9/+9
| | | | CamelCase is ugly... rename all functions.
* song: replaced all song constructorsMax Kellermann2008-10-111-2/+2
| | | | | | Provide separate constructors for creating a remote song, a local song, and one for loading data from a song file. This way, we can add more assertions.
* playlist: simplified setPlaylistRandomStatus()Max Kellermann2008-10-111-5/+1
| | | | | Check the old status before assigning. This saves a temporary variable.
* song: converted typedef Song to struct songMax Kellermann2008-10-111-13/+14
| | | | | | | | | | | | | | | Again, a data type which can be forward-declared. [ew: * used "struct mpd_song" instead to avoid token duplication (like I did with "struct mpd_tag") as there's no good abbreviation for "song" and identical tokens on the same line don't read well * rewritten using perl -i -p -e 's/\bSong\b/struct mpd_song/g' src/*.[ch] since it was too hard to merge * also, I don't care much for forward declarations ]
* song: replace printSong* with song_print_*Eric Wong2008-10-051-2/+2
| | | | | | This make argument order more consistent for iterators. Additionally, these now return ssize_t results for error checking.
* song: stop storing song_typeEric Wong2008-10-051-8/+8
| | | | | | | We already know if a song is a URL or not based on whether it has parentDir defined or not. Hopefully one day in the future we can drop HTTP support from MPD entirely when an HTTP filesystem comes along and we can access streams via open(2).
* Merge commit '1533279fb18b2b0f53345f0e0727d2f0f968c00d'Eric Wong2008-10-051-92/+50
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '1533279fb18b2b0f53345f0e0727d2f0f968c00d': directory: reuse existing directory if found on update song: better handling of existing songs when rereading DB tag: merge clearMpdTag into tag_free song: start avoiding race in updateSongInfo command: get rid of specialized list handlers directory: simplify list update handling logic main_notify: define main_task so we can use it for assertions directory: streamline deletes song: start avoiding race in updateSongInfo playlist: small lines of code reduction Revert "Start using song pointers in core data structures" Conflicts: src/playlist.c
| * playlist: small lines of code reductionEric Wong2008-10-031-96/+47
| | | | | | | | Hopefully this makes the code feel less claustrophobic...
| * Revert "Start using song pointers in core data structures"Eric Wong2008-10-021-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.
* | playlist: fix "currentsong" at end-of-playlistEric Wong2008-10-041-4/+11
|/ | | | | | | The current song information could get cleared if we got to the end of the playlist and mpd is not in repeat mode. This also prevents "currentsong" from returning information if mpd is not playing.
* Switch to C99 types (retaining compat with old compilers)Eric Wong2008-09-291-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.
* playlist: deleteASongFromPlaylist takes a const Song *Eric Wong2008-09-281-1/+1
| | | | We don't change the song pointer there, either.
* playlist: fix currentsong info after swapping songsEric Wong2008-09-281-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.
* playlist: reset after we've hit the endEric Wong2008-09-281-0/+6
| | | | | If repeat is off, we reset (and reshuffle in random mode) the playlist.
* advance to the next song on decoder errorsEric Wong2008-09-281-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.
* start using prefixcmp()Eric Wong2008-09-201-23/+8
| | | | | LOC reduction and less noise makes things easier for tired old folks to follow.
* Move away from fprintf() when writing DB/state_fileEric Wong2008-09-181-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...
* 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