aboutsummaryrefslogtreecommitdiffstats
path: root/src (unfollow)
Commit message (Collapse)AuthorFilesLines
2008-04-12make variables more localMax Kellermann1-4/+3
Declare the variables "test" and "fadePosition" in the scope where they are really used. This removes some of the clutter in the function decodeParent(). git-svn-id: https://svn.musicpd.org/mpd/trunk@7261 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12moved the initial buffering code into the big loopMax Kellermann1-13/+10
Eliminating some duplicated and. This also decreases the number of lines calling processDecodeInput(). git-svn-id: https://svn.musicpd.org/mpd/trunk@7260 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12some comments in decode.cMax Kellermann1-0/+39
I have spent some time to understand decodeParent(), which does a lot of obfuscated magic... I find it useful to help others to also understand it, so I wrote a few comments. git-svn-id: https://svn.musicpd.org/mpd/trunk@7259 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12integrated macro handleDecodeStart() into callerMax Kellermann1-43/+40
Another patch indended to improve the CPP macro hell. This enlarges the function decodeParent(), but it cannot be converted into a standalone function easily, because it references so many local variables. git-svn-id: https://svn.musicpd.org/mpd/trunk@7258 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12use clearOutputBuffer()Max Kellermann1-4/+2
clearOutputBuffer() also resets currentChunk; this might resolve a theoretical bug. git-svn-id: https://svn.musicpd.org/mpd/trunk@7257 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12do not check dc->start after loopMax Kellermann1-1/+1
dc->start cannot be true after the loop, because it was the loop condition. dc->start could have been set by another thread between the while loop and the if, but I suspect this is not the case the author intended, so we just remove the dc->start check. git-svn-id: https://svn.musicpd.org/mpd/trunk@7256 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12use DECODE_ERROR_NOERROR instead of 0Max Kellermann1-3/+3
In my opinion, the code becomes more readable when we explicitly check "==NOERROR" instead of an implicit 0 check. git-svn-id: https://svn.musicpd.org/mpd/trunk@7255 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12converted macro processDecodeInput() to functionMax Kellermann1-52/+80
Macros are ugly, and multi-line macros are even more ugly. This patch converts processDecodeInput() to a C function. The disadvantage may be that the function does not have access to the caller's local variables, which might be regarded as an advantage on the other hand. For this reason, we have to pass variable references. This costs a tiny bit of performance, but it's worth eliminating this monster macro, and further patches will optimize this cost down. git-svn-id: https://svn.musicpd.org/mpd/trunk@7254 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-04-12don't set quit=1 before breakMax Kellermann1-5/+2
Instead of setting quit=1, we can simply break out of the loop. git-svn-id: https://svn.musicpd.org/mpd/trunk@7252 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12simplified some code in decode.cMax Kellermann1-11/+10
The block after "if" breaks out of the loop. To make the code a little bit more readable, don't write the rest in an "else" block, since this code path does not break. git-svn-id: https://svn.musicpd.org/mpd/trunk@7251 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12add method availableOutputBuffer()Max Kellermann3-2/+12
The method availableOutputBuffer() calculates how many chunks are in use. This simplifies code which needs this information, and it can run without knowing OutputBuffer internals. The function knows how to calculate this when begin>end; this might have been a bug in decodeParent(), which does not. git-svn-id: https://svn.musicpd.org/mpd/trunk@7250 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12replace advanceOutputBufferTo() with trivial assignmentMax Kellermann1-6/+1
After the previous patch, it is clear that the loop in advanceOutputBufferTo() can be replaced with a simple assignment. git-svn-id: https://svn.musicpd.org/mpd/trunk@7249 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12removed unused parameters from advanceOutputBufferTo()Max Kellermann1-6/+2
The parameter "currentChunkSent" is not used and can be dropped. git-svn-id: https://svn.musicpd.org/mpd/trunk@7248 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12moved code to function tailChunk()Max Kellermann1-33/+58
This patch removes some clutter from decodeParent() by moving some code out. git-svn-id: https://svn.musicpd.org/mpd/trunk@7247 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12use free()+malloc() instead of realloc()Max Kellermann1-1/+3
realloc() has to copy data to the new buffer. Since convBuffer contains temporary data only, we can safely use free() plus a new malloc(), which saves the mempy(). git-svn-id: https://svn.musicpd.org/mpd/trunk@7246 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12some documentation about OutputBufferMax Kellermann1-0/+9
git-svn-id: https://svn.musicpd.org/mpd/trunk@7245 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12Start using song pointers in core data structuresEric Wong5-66/+53
Instead of copying URLs everywhere... [merged r7186 from branches/ew] git-svn-id: https://svn.musicpd.org/mpd/trunk@7244 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12outputBuffer: remove unused variableEric Wong1-1/+0
[merged r7185 from branches/ew] git-svn-id: https://svn.musicpd.org/mpd/trunk@7243 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12song: document get_song_url()Eric Wong1-0/+6
[merged r7184 from branches/ew] git-svn-id: https://svn.musicpd.org/mpd/trunk@7242 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12Drop metadata updates from HTTP for now (input HTTP, and shout)Eric Wong11-328/+7
It is way more complicated than it should be; and locking it for thread-safety is too difficult. [merged r7183 from branches/ew] git-svn-id: https://svn.musicpd.org/mpd/trunk@7241 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12Initial cut of fork() => pthreads() for decoder and playerEric Wong21-377/+212
I initially started to do a heavy rewrite that changed the way processes communicated, but that was too much to do at once. So this change only focuses on replacing the player and decode processes with threads and using condition variables instead of polling in loops; so the changeset itself is quiet small. * The shared output buffer variables will still need locking to guard against race conditions. So in this effect, we're probably just as buggy as before. The reduced context-switching overhead of using threads instead of processes may even make bugs show up more or less often... * Basic functionality appears to be working for playing local (and NFS) audio, including: play, pause, stop, seek, previous, next, and main playlist editing * I haven't tested HTTP streams yet, they should work. * I've only tested ALSA and Icecast. ALSA works fine, Icecast metadata seems to get screwy at times and breaks song advancement in the playlist at times. * state file loading works, too (after some last-minute hacks with non-blocking wakeup functions) * The non-blocking (*_nb) variants of the task management functions are probably overused. They're more lenient and easier to use because much of our code is still based on our previous polling-based system. * It currently segfaults on exit. I haven't paid much attention to the exit/signal-handling routines other than ensuring it compiles. At least the state file seems to work. We don't do any cleanups of the threads on exit, yet. * Update is still done in a child process and not in a thread. To do this in a thread, we'll need to ensure it does proper locking and communication with the main thread; but should require less memory in the end because we'll be updating the database "in-place" rather than updating a copy and then bulk-loading when done. * We're more sensitive to bugs in 3rd party libraries now. My plan is to eventually use a master process which forks() and restarts the child when it dies: locking and communication with the main thread; but should require less memory in the end because we'll be updating the database "in-place" rather than updating a copy and then bulk-loading when done. * We're more sensitive to bugs in 3rd party libraries now. My plan is to eventually use a master process which forks() and restarts the child when it dies: master - just does waitpid() + fork() in a loop \- main thread \- decoder thread \- player thread At the beginning of every song, the main thread will set a dirty flag and update the state file. This way, if we encounter a song that triggers a segfault killing the main thread, the master will start the replacement main on the next song. * The main thread still wakes up every second on select() to check for signals; which affects power management. [merged r7138 from branches/ew] git-svn-id: https://svn.musicpd.org/mpd/trunk@7240 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12whitespace cleanupMax Kellermann2-8/+8
Clean up some space indentations, replace with tabs. git-svn-id: https://svn.musicpd.org/mpd/trunk@7239 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12proper bind error message for unix socketMax Kellermann1-1/+2
git-svn-id: https://svn.musicpd.org/mpd/trunk@7238 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12provide switches for TCP and unix socketsMax Kellermann3-1/+24
autoconf flags for enabling and disabling TCP and unix domain socket support. Embedded machines without a TCP stack may be better off without TCP support. git-svn-id: https://svn.musicpd.org/mpd/trunk@7236 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12support listening on unix domain socketsMax Kellermann2-0/+17
This trivial patch addresses bug 1639. When a bind_to_address argument starts with a slash, assume that it is the address of a Unix domain socket. git-svn-id: https://svn.musicpd.org/mpd/trunk@7235 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12use constant pointers when possibleMax Kellermann3-25/+24
It is a good practice to constify pointers when their dereferenced data is not modified within the functions or its descendants. git-svn-id: https://svn.musicpd.org/mpd/trunk@7234 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12eliminate unused parametersMax Kellermann1-6/+5
The parameter "port" is not actually used by establishListen(), and can be removed. This also allows establishListen() to be used for socket addresses which have no port. git-svn-id: https://svn.musicpd.org/mpd/trunk@7233 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12unsigned integers in playerData.[ch]Max Kellermann2-6/+5
The number of buffered chunks can obviously not become negative. The "buffered_before_play<0" therefore cannot be useful, so let's remove it, too. git-svn-id: https://svn.musicpd.org/mpd/trunk@7232 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12use unsigned integers in outputBuffer.cMax Kellermann2-3/+3
The chunk index cannot be negative. git-svn-id: https://svn.musicpd.org/mpd/trunk@7231 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12fix sign compare warningsMax Kellermann4-10/+10
Do explicit casts before comparing signed with unsigned. The one in log.c actually fixes another warning: in the expanded macro, there may be a check "logLevel>=0", which is always true. git-svn-id: https://svn.musicpd.org/mpd/trunk@7230 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12deconstify input buffer for iconv()Max Kellermann1-2/+18
Unfortunately, the function iconv() wants a non-const input buffer. In this context, we only have a const pointer, which emits a correct gcc warning. Work around this ugliness with an union-deconst hack. This is optimized away in the binary. git-svn-id: https://svn.musicpd.org/mpd/trunk@7229 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12use unsigned integers in the flac pluginMax Kellermann2-2/+2
The counter variables c_samp and c_chan begin at zero and can never be negative. git-svn-id: https://svn.musicpd.org/mpd/trunk@7228 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12removed unused variableMax Kellermann2-6/+6
The local variable d_samp is initialized, but never actually used. git-svn-id: https://svn.musicpd.org/mpd/trunk@7227 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12use unsigned integers in decoder.cMax Kellermann1-5/+5
Use unsigned integers in decoderParent() for chunk numbers which cannot be negative. git-svn-id: https://svn.musicpd.org/mpd/trunk@7226 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-30include os_compat.h in tarball distributionsEric Wong1-0/+1
Thanks to Jérome Perrin git-svn-id: https://svn.musicpd.org/mpd/trunk@7224 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-27notify: initialize variable to keep valgrind from bitchingEric Wong1-1/+1
We don't really care what that variable is, so it might as well be uninitialized, but valgrind does... git-svn-id: https://svn.musicpd.org/mpd/trunk@7220 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26notify: more cleanups, add error checking for pipe errorsEric Wong2-9/+10
Don't bother initializing the junk buffer, we really don't care. The array was also unnecessary and ugly. Also, avoid returning the byte count we read/wrote since it unnecessarily exposes internal details of the implementation to the callers. git-svn-id: https://svn.musicpd.org/mpd/trunk@7219 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26interface: use a saner fdmax for select(2) when closing errored interfacesEric Wong1-1/+2
git-svn-id: https://svn.musicpd.org/mpd/trunk@7218 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26notify: cleanupsEric Wong7-41/+31
* move set_nonblock{,ing}() into utils.c since we use it elsewhere, too * add proper error checking to set_nonblocking() * use os_compat.h instead of individually #includ-ing system headers git-svn-id: https://svn.musicpd.org/mpd/trunk@7217 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26send notify signal after SIGCONTMax Kellermann1-0/+2
When the decoder receives SIGCONT during waitNotify(), the kernel restarts the read() system call. This lets the decoder process block indefinitely, while the player process waits for it to react. This should probably be solved with a proper signal handler which aborts the read() system call, but for now, we just write to the pipe to make it wake up. git-svn-id: https://svn.musicpd.org/mpd/trunk@7216 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26notify the decoder instead of polling 100hzMax Kellermann6-1/+125
When the decoder process is faster than the player process, all decodedd buffers are full at some point in time. The decoder has to wait for buffers to become free (finished playing). It used to do this by polling the buffer status 100 times a second. This generates a lot of unnecessary CPU wakeups. This patch adds a way for the player process to notify the decoder process that it may continue its work. We could use pthread_cond for that, unfortunately inter-process mutexes/conds are not supported by some kernels (Linux), so we cannot use this light-weight method until mpd moves to using threads instead of processes. The other method would be semaphores, which historically are global resources with a unique name; this historic API is cumbersome, and I wanted to avoid it. I came up with a quite naive solution for now: I create an anonymous pipe with pipe(), and the decoder process reads on that pipe. Until the player process sends data on it as a signal, the decoder process blocks. This can be optimized in a number of ways: - if the decoder process is still working (instead of waiting for buffers), we could save the write() system call, since there is nobody waiting for the notification. [ew: I tried this using a counter in shared memory, didn't help] - the pipe buffer will be full at some point, when the decoder thread is too slow. For this reason, the writer side of the pipe is non-blocking, and mpd can ignore the resulting EWOULDBLOCK. - since we have shared memory, we could check whether somebody is actually waiting without a context switch, and we could just not write the notification byte. [ew: tried same method/result as first point above] - if there is already a notification in the pipe, we could also not write another one. [ew: tried same method/result as first/third points above] - the decoder will only consume 64 bytes at a time. If the pipe buffer is full, this will result in a lot of read() invocations. This does not hurt badly, but on a heavily loaded system, this might add a little bit more load. The preceding optimizations however are able eliminate the this. - finally, we should use another method for inter process notifications - maybe kill() or just make mpd use threads, finally. In spite of all these possibilities to optimize this code further, this pipe notification trick is faster than the 100 Hz poll. On my machine, it reduced the number of wakeups to less than 30%. git-svn-id: https://svn.musicpd.org/mpd/trunk@7215 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26unsigned countersMax Kellermann2-13/+13
Use unsigned variables for storing the count of items or for iteration variables. Since there can never be a negative number of items, it makes sense to use an unsigned data type here. This change is safe because the unsigned values are only used for adddressing array items. git-svn-id: https://svn.musicpd.org/mpd/trunk@7214 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26don't repeat select()Max Kellermann1-5/+2
The interfaces main loop repeats the select() (non-blocking) after an event was handled. I do not see any reason for that, since all events should be handled after the first select(). This double select() does nothing than consume more CPU cycles. git-svn-id: https://svn.musicpd.org/mpd/trunk@7213 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26unlimited select() timeoutMax Kellermann1-5/+3
mpd sets a 1s select() timeout for no reason. This makes mpd wake up the CPU, consume some cycles just to see there is nothing to do. We can save that by specifying NULL instead of a timeout. git-svn-id: https://svn.musicpd.org/mpd/trunk@7212 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26wavpack_plugin: cleanups after the last commitEric Wong1-2/+2
* malloc() => xmalloc() for error checking * strncpy() replaced with memcpy(), memcpy appears perfectly safe here and mpd does not ever use strncpy() (see r4491) git-svn-id: https://svn.musicpd.org/mpd/trunk@7211 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26WavPack improvementsLaszlo Ashin1-29/+130
This patch does the following: -enables WVC support for streams as well, -improves MPD inputStream <=> WavPack stream connector, -fixes two compile warnings (which were caused by MPD API change). Mantis #1660 <http://musicpd.org/mantis/view.php?id=1660> git-svn-id: https://svn.musicpd.org/mpd/trunk@7210 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26networking: more assertions and cleanups to size_t/unsigned changesEric Wong2-48/+58
Basically, I don't trust myself nor Max to not have bugs in our code when switching over to unsigned types, so I've added more assertions which will hopefully trip and force us to fix these bugs before somebody can exploit them :) Some cleanups for parameter parsing using strtol and error reporting to the user. Also, fix some completely garbled indentation in inputStream_http.c git-svn-id: https://svn.musicpd.org/mpd/trunk@7209 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26audio.c: unsigned int functions return unsigned ints, not size_tEric Wong1-1/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@7208 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26audiofile_plugin: fix nasty long lines introduced in previous commitEric Wong1-2/+4
Terminals are 80 columns and that's a hard limit, no exceptions git-svn-id: https://svn.musicpd.org/mpd/trunk@7207 09075e82-0dd4-0310-85a5-a0d7c8717e4f