aboutsummaryrefslogtreecommitdiffstats
path: root/src/outputBuffer.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* notify the decoder instead of polling 100hzMax Kellermann2008-03-261-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
* moved code to initOutputBuffer()Max Kellermann2008-03-261-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
* use size_tMax Kellermann2008-03-261-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
* fixed -Wshadow warningsMax Kellermann2008-01-261-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
* Cleanup #includes of standard system headers and put them in one placeEric Wong2008-01-031-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
* Make pcm_convertAudioFormat return the buffer size. This is necessaryJ. Alexander Treuman2007-05-261-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
* Reverting to the full lsr API. Turns out the simple API needs all of theJ. Alexander Treuman2007-05-241-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
* Split pcm_convertAudioFormat into separate functions for bitrate, channel,J. Alexander Treuman2007-05-221-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
* The massive copyright updateAvuton Olrich2007-04-051-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@5834 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* #1) fix a few potential deadlock conditons in decode.c when crossfading is ↵Warren Dukes2007-02-111-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
* Don't initialize globals to zero (or NULL)Eric Wong2007-01-141-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
* outputBuffer: avoid out-of-bounds-error in clearOutputBuffer()Eric Wong2006-09-211-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
* Replace strdup and {c,re,m}alloc with x* variants to check for OOM errorsEric Wong2006-08-261-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
* Use AudioCompress for volume normalizationJ. Alexander Treuman2006-07-271-19/+2
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@4474 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Do normalization if there's replaygain data but replaygain is offJ. Alexander Treuman2006-07-241-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@4445 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Adding on the fly volume normalization support. Code originally from ↵J. Alexander Treuman2006-07-221-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
* Add mpd-indent.shAvuton Olrich2006-07-201-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
* Remove useless buffer signedness warnings, useAvuton Olrich2006-07-191-1/+1
| | | | | void * rather than "x char *" git-svn-id: https://svn.musicpd.org/mpd/trunk@4408 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Change shank's email addressJ. Alexander Treuman2006-07-141-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@4333 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Huge header update, update the copyright and addAvuton Olrich2006-07-131-1/+1
| | | | | the GPL header where necessary git-svn-id: https://svn.musicpd.org/mpd/trunk@4317 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Don't rely on memcmp() for structs, padding bits are randomEric Wong2006-04-051-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@4016 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* src/outputBuffer.c: bugfix: freeMpdTag(), not just free()Eric Wong2006-03-191-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@3930 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* print out bits in debug message output for OSS and ALSAWarren Dukes2005-03-191-1/+3
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@3104 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* rewrite replaygain code, needs testingWarren Dukes2004-11-021-1/+4
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@2482 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* configure shout encoding quality and audio formatWarren Dukes2004-10-231-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@2307 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* very minor tweak to clearMetabufferChunksWarren Dukes2004-06-241-5/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1650 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* uber minor tweaksWarren Dukes2004-06-191-3/+4
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1563 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* fix some streaming metadata issuesWarren Dukes2004-06-091-1/+10
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1416 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* remove "wrap" from buffering control, its not needed, and could potentiallyWarren Dukes2004-06-081-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
* remove metadata debugging codeWarren Dukes2004-06-071-7/+0
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1378 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* bug fix for metadata again, had an extra "!" in mpdTagsAreEqual()Warren Dukes2004-06-071-4/+8
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1371 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* some fixes to metadata stuffWarren Dukes2004-06-071-0/+11
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1370 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* potential bugfixes for handling metadata in player/decoderWarren Dukes2004-06-071-5/+10
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1369 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* harden metadatabufferWarren Dukes2004-06-061-3/+26
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1362 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* spelling fix for avutonWarren Dukes2004-06-061-2/+4
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1361 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* mechanism for updating metadata while decodingWarren Dukes2004-06-061-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
* todo updateWarren Dukes2004-06-061-1/+30
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1352 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* fixed seek, its now blocking againWarren Dukes2004-05-301-3/+6
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1237 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* fix TIcho's seeking while paused bugWarren Dukes2004-05-291-2/+8
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1225 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* undo last changesWarren Dukes2004-05-281-3/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1217 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* fix seeking more than once when paused, by returning immediatly on dc->seekWarren Dukes2004-05-281-1/+3
| | | | | in sendToOutputBuffer git-svn-id: https://svn.musicpd.org/mpd/trunk@1216 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* do input buffering in while sleeping loop of sending stuff to output bufferWarren Dukes2004-05-211-3/+8
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1125 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* another bug fix for non-blocking seekWarren Dukes2004-05-201-2/+2
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@1103 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* non-blocking seeking, needs some testing! (this is not just for streamsWarren Dukes2004-05-191-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
* yes! rudimentary stream playing for mp3's!Warren Dukes2004-05-181-0/+6
| | | | | be gentle git-svn-id: https://svn.musicpd.org/mpd/trunk@1051 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* more little bits of code in prep for resample/audioFormat conversion,Warren Dukes2004-05-101-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
* rewrite outputBuffer'ing abstraction a bit to be more effecient and easierWarren Dukes2004-05-071-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
* new OutputBuffer abstraction stuff, implemented for mp3, now need toWarren Dukes2004-05-071-7/+3
| | | | | implement in other decoders git-svn-id: https://svn.musicpd.org/mpd/trunk@940 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* some begging code of abstracting out some simple buffer routine(s) for decodersWarren Dukes2004-05-071-0/+66
git-svn-id: https://svn.musicpd.org/mpd/trunk@928 09075e82-0dd4-0310-85a5-a0d7c8717e4f