aboutsummaryrefslogtreecommitdiffstats
path: root/src/outputBuffer.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2008-04-12fix sign compare warningsMax Kellermann1-1/+1
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-03-26notify the decoder instead of polling 100hzMax Kellermann1-1/+3
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-26moved code to initOutputBuffer()Max Kellermann1-0/+17
This patch moves code which initializes the OutputBuffer struct to outputBuffer.c. Although this is generally a good idea, it prepares the following patch. git-svn-id: https://svn.musicpd.org/mpd/trunk@7206 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26use size_tMax Kellermann1-2/+2
When dealing with in-memory lengths, the standard type "size_t" should be used. Missing one can be quite dangerous, because an attacker could provoke an integer under-/overflow, which may provide an attack vector. git-svn-id: https://svn.musicpd.org/mpd/trunk@7205 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26fixed -Wshadow warningsMax Kellermann1-2/+2
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-3/+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
2007-05-26Make pcm_convertAudioFormat return the buffer size. This is necessaryJ. Alexander Treuman1-3/+3
because lsr may return less than the input buffer size, and the rest of the audio code needs to know the new size. This fixes the clicking that was introduced with recent changes to the lsr code. A huge thanks to remiss for figuring this out. git-svn-id: https://svn.musicpd.org/mpd/trunk@6273 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-24Reverting to the full lsr API. Turns out the simple API needs all of theJ. Alexander Treuman1-1/+2
audio at once, so it won't work for us. The old full API code was still heavily broken, as each call to pcm_convertSampleRate() used the same state, even if it was processing two streams of audio. The new code keeps a separate state for each audio stream that's being converted. git-svn-id: https://svn.musicpd.org/mpd/trunk@6255 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-22Split pcm_convertAudioFormat into separate functions for bitrate, channel,J. Alexander Treuman1-7/+2
and samplerate conversion. This makes the code much easier to read, and fixes a few bugs that were previously there. git-svn-id: https://svn.musicpd.org/mpd/trunk@6224 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-04-05The massive copyright updateAvuton Olrich1-1/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@5834 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-02-11#1) fix a few potential deadlock conditons in decode.c when crossfading is ↵Warren Dukes1-4/+3
enabled #2) fix a deadlock condition when attempting to seek if the decoder quit and returned to playerInit() git-svn-id: https://svn.musicpd.org/mpd/trunk@5325 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-01-14Don't initialize globals to zero (or NULL)Eric Wong1-4/+4
Some compilers and linkers aren't smart enough to optimize this, as global variables are implictly initialized to zero. As a result, binaries are a bit smaller as more goes in the .bss and less in the text section. git-svn-id: https://svn.musicpd.org/mpd/trunk@5254 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-09-21outputBuffer: avoid out-of-bounds-error in clearOutputBuffer()Eric Wong1-3/+3
I'm still not entirely certain why we index cb->metaChunkSet[] with currentChunk (and not currentMetaChunk), but shank told me that currentChunk is correct... git-svn-id: https://svn.musicpd.org/mpd/trunk@4814 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-26Replace strdup and {c,re,m}alloc with x* variants to check for OOM errorsEric Wong1-1/+1
I'm checking for zero-size allocations and assert()-ing them, so we can more easily get backtraces and debug problems, but we'll also allow -DNDEBUG people to live on the edge if they wish. We do not rely on errno when checking for OOM errors because some implementations of malloc do not set it, and malloc is commonly overridden by userspace wrappers. I've spent some time looking through the source and didn't find any obvious places where we would explicitly allocate 0 bytes, so we shouldn't trip any of those assertions. We also avoid allocating zero bytes because C libraries don't handle this consistently (some return NULL, some not); and it's dangerous either way. git-svn-id: https://svn.musicpd.org/mpd/trunk@4690 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-27Use AudioCompress for volume normalizationJ. Alexander Treuman1-19/+2
git-svn-id: https://svn.musicpd.org/mpd/trunk@4474 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-24Do normalization if there's replaygain data but replaygain is offJ. Alexander Treuman1-1/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@4445 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-22Adding on the fly volume normalization support. Code originally from ↵J. Alexander Treuman1-0/+20
mplayer, ported by syscrash, cleaned up by avuton, and further cleaned up by me (jat). git-svn-id: https://svn.musicpd.org/mpd/trunk@4424 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-20Add mpd-indent.shAvuton Olrich1-77/+84
Indent the entire tree, hopefully we can keep it indented. git-svn-id: https://svn.musicpd.org/mpd/trunk@4410 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-19Remove useless buffer signedness warnings, useAvuton Olrich1-1/+1
void * rather than "x char *" git-svn-id: https://svn.musicpd.org/mpd/trunk@4408 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-14Change shank's email addressJ. Alexander Treuman1-1/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@4333 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-13Huge header update, update the copyright and addAvuton Olrich1-1/+1
the GPL header where necessary git-svn-id: https://svn.musicpd.org/mpd/trunk@4317 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-04-05Don't rely on memcmp() for structs, padding bits are randomEric Wong1-1/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@4016 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-03-19src/outputBuffer.c: bugfix: freeMpdTag(), not just free()Eric Wong1-1/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@3930 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2005-03-19print out bits in debug message output for OSS and ALSAWarren Dukes1-1/+3
git-svn-id: https://svn.musicpd.org/mpd/trunk@3104 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-11-02rewrite replaygain code, needs testingWarren Dukes1-1/+4
git-svn-id: https://svn.musicpd.org/mpd/trunk@2482 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-10-23configure shout encoding quality and audio formatWarren Dukes1-1/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@2307 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-24very minor tweak to clearMetabufferChunksWarren Dukes1-5/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@1650 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-19uber minor tweaksWarren Dukes1-3/+4
git-svn-id: https://svn.musicpd.org/mpd/trunk@1563 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-09fix some streaming metadata issuesWarren Dukes1-1/+10
git-svn-id: https://svn.musicpd.org/mpd/trunk@1416 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-08remove "wrap" from buffering control, its not needed, and could potentiallyWarren Dukes1-4/+5
create a race condition (but hasn't happened in the last 10 months since this code was written) git-svn-id: https://svn.musicpd.org/mpd/trunk@1397 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-07remove metadata debugging codeWarren Dukes1-7/+0
git-svn-id: https://svn.musicpd.org/mpd/trunk@1378 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-07bug fix for metadata again, had an extra "!" in mpdTagsAreEqual()Warren Dukes1-4/+8
git-svn-id: https://svn.musicpd.org/mpd/trunk@1371 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-07some fixes to metadata stuffWarren Dukes1-0/+11
git-svn-id: https://svn.musicpd.org/mpd/trunk@1370 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-07potential bugfixes for handling metadata in player/decoderWarren Dukes1-5/+10
git-svn-id: https://svn.musicpd.org/mpd/trunk@1369 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-06harden metadatabufferWarren Dukes1-3/+26
git-svn-id: https://svn.musicpd.org/mpd/trunk@1362 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-06spelling fix for avutonWarren Dukes1-2/+4
git-svn-id: https://svn.musicpd.org/mpd/trunk@1361 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-06mechanism for updating metadata while decodingWarren Dukes1-27/+21
vorbis comments are updated on the fly for streams need to decode icy metadata buffering of metadata needs to be hardened, to ensure that player has already read a particular metachunk or passed over it git-svn-id: https://svn.musicpd.org/mpd/trunk@1358 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-06todo updateWarren Dukes1-1/+30
git-svn-id: https://svn.musicpd.org/mpd/trunk@1352 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-30fixed seek, its now blocking againWarren Dukes1-3/+6
git-svn-id: https://svn.musicpd.org/mpd/trunk@1237 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-29fix TIcho's seeking while paused bugWarren Dukes1-2/+8
git-svn-id: https://svn.musicpd.org/mpd/trunk@1225 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-28undo last changesWarren Dukes1-3/+1
git-svn-id: https://svn.musicpd.org/mpd/trunk@1217 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-28fix seeking more than once when paused, by returning immediatly on dc->seekWarren Dukes1-1/+3
in sendToOutputBuffer git-svn-id: https://svn.musicpd.org/mpd/trunk@1216 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-21do input buffering in while sleeping loop of sending stuff to output bufferWarren Dukes1-3/+8
git-svn-id: https://svn.musicpd.org/mpd/trunk@1125 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-20another bug fix for non-blocking seekWarren Dukes1-2/+2
git-svn-id: https://svn.musicpd.org/mpd/trunk@1103 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-19non-blocking seeking, needs some testing! (this is not just for streamsWarren Dukes1-3/+1
but new code for files seeking as well) git-svn-id: https://svn.musicpd.org/mpd/trunk@1099 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-18yes! rudimentary stream playing for mp3's!Warren Dukes1-0/+6
be gentle git-svn-id: https://svn.musicpd.org/mpd/trunk@1051 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-10more little bits of code in prep for resample/audioFormat conversion,Warren Dukes1-1/+23
now to just write the actual audioFormat conversion code! git-svn-id: https://svn.musicpd.org/mpd/trunk@970 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-07rewrite outputBuffer'ing abstraction a bit to be more effecient and easierWarren Dukes1-24/+42
to interface. Also, use outputBuffer abstraction for ogg git-svn-id: https://svn.musicpd.org/mpd/trunk@941 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-07new OutputBuffer abstraction stuff, implemented for mp3, now need toWarren Dukes1-7/+3
implement in other decoders git-svn-id: https://svn.musicpd.org/mpd/trunk@940 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-07some begging code of abstracting out some simple buffer routine(s) for decodersWarren Dukes1-0/+66
git-svn-id: https://svn.musicpd.org/mpd/trunk@928 09075e82-0dd4-0310-85a5-a0d7c8717e4f