Commit Graph

1874 Commits

Author SHA1 Message Date
Eric Wong
06bdc5bf25 introduce struct condition as a more correct version of Notify
Start using it in the HTTP code

git-svn-id: https://svn.musicpd.org/mpd/trunk@7395 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:43:22 +00:00
Eric Wong
d82a4aff25 utils: pthread_{mutex,cond}_init can fail, so check for it
git-svn-id: https://svn.musicpd.org/mpd/trunk@7394 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:43:17 +00:00
Eric Wong
2a5dcba5ed http: initial rewrite using ringbuffer + pthreads
This institutes the usage of a separate thread to buffer HTTP
input.  It is basically practice code for using the ringbuffer
code which I plan on reusing for the OutputBuffer as well as
further input buffering for disk (networked filesystems over
WAN, laptops on battery, etc).

Each readFromInputStream() call on an HTTP stream can take
several seconds to complete, short reads are avoided.

A single-threaded solution for systems supporting large enough
SO_RCVBUF values should also be possible and will likely be done
in the future; but this lock-free(except when full/empty)
ringbuffer is cool :)

git-svn-id: https://svn.musicpd.org/mpd/trunk@7393 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:43:13 +00:00
Eric Wong
c71cfbac7a http: fix some small memory leaks when hitting redirects
git-svn-id: https://svn.musicpd.org/mpd/trunk@7392 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:43:08 +00:00
Eric Wong
8426740f44 utils: add new unforgiving utility functions
We'll be using pipes when waiting for I/O, and condition
variables at other times.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7391 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:43:04 +00:00
Eric Wong
c593152967 ringbuf: add thread-safe, thread-specific reset functions
This will allow both the reader and writer threads to
reset the ringbuffer in a thread-safe fashion.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7390 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:42:59 +00:00
Eric Wong
9873e07c5a ringbuf: get_{write,read}_vector returns total bytes in both vec elts
This will eliminate unnecessary calls to ringbuf_{read,write}_space

git-svn-id: https://svn.musicpd.org/mpd/trunk@7389 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:42:55 +00:00
Eric Wong
aa828c1b25 http: split out logic around getaddrinfo() and connect()
Makes code easier to read and modularize

git-svn-id: https://svn.musicpd.org/mpd/trunk@7388 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:42:49 +00:00
Eric Wong
ec1eeeeaff http: split out auth code since it's mostly uninteresting for now
The auth code also has some ugly usages of string generation
which I will eventually replace with something nicer...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7387 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:42:45 +00:00
Eric Wong
bec0835836 Add a generic ring buffer implementation
This piece of code is from the JACK Audio Connection Kit
(trimmed down a bit for better readability).

The vector functions now reuse the common iovec struct used by
writev/readv instead of reinventing an identical but
differently-named struct.

From the comments:
> ISO/POSIX C version of Paul Davis's lock free ringbuffer C++ code.
> This is safe for the case of one read thread and one write thread.

License is LGPL 2.1 or later

git-svn-id: https://svn.musicpd.org/mpd/trunk@7386 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:42:40 +00:00
Eric Wong
3a932bf388 os_compat.h: add sys/uio.h for writev/readv
vectored I/O will be useful with our ring buffer lib

git-svn-id: https://svn.musicpd.org/mpd/trunk@7385 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:42:34 +00:00
Jim Ramsay
72434d212c Die if a specific backend is requested but not found.
git-svn-id: https://svn.musicpd.org/mpd/trunk@7382 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-16 13:43:03 +00:00
Max Kellermann
d1b4112f45 jack: initialize audioOutput->data
Initialize audioOutput->data with NULL in jack_initDriver().
Previously, this was never initialized, although the other functions
relied on it being NULL prior to jack_openDevice().

This patch addresses bug 0001641[1].  In contrast to the patch provided
by the bug reporter, it moves the initialization before the "!param"
check.

[1] - http://musicpd.org/mantis/view.php?id=1641

git-svn-id: https://svn.musicpd.org/mpd/trunk@7375 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-13 07:39:11 +00:00
Hans de Goede
4f247ca4da mod: fix crashing on modtracker files
This patch was taken from
http://bugzilla.livna.org/show_bug.cgi?id=1987 and addresses bug
0001693[1]

[1] - http://musicpd.org/mantis/view.php?id=1693

git-svn-id: https://svn.musicpd.org/mpd/trunk@7374 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-13 07:39:05 +00:00
Eric Wong
29df78fe1e audio.c: avoid magic numbers even if they have comments :)
git-svn-id: https://svn.musicpd.org/mpd/trunk@7373 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-02 10:10:32 +00:00
Eric Wong
f57be50d73 remove audioDeviceStates from playerData and getPlayerData
git-svn-id: https://svn.musicpd.org/mpd/trunk@7372 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-02 10:10:26 +00:00
Max Kellermann
6ac1d797af fix stream URL
Streaming was broken, beacuse the stream URL was never copied to
path_max_fs.

[ew: replaced strcpy with pathcpy_trunc for ease of auditing]

git-svn-id: https://svn.musicpd.org/mpd/trunk@7371 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-01 22:25:20 +00:00
Eric Wong
56aab937d0 oggflac_plugin: fix build with libOggFLAC lib (libFLAC <= 7)
git-svn-id: https://svn.musicpd.org/mpd/trunk@7370 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-01 22:25:07 +00:00
Max Kellerman
7f6a44ef8e make DecoderControl.state an enum
git-svn-id: https://svn.musicpd.org/mpd/trunk@7369 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-01 22:25:00 +00:00
Eric Wong
8a4dff14ad Add the bs build system from mpd-ke
Dealing with autotools is too painful when having
to deal with multiple build environments and
configurations.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7368 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-01 22:24:55 +00:00
Max Kellerman
97698bd4aa notify: don't use camelCase in notify.[ch]
git-svn-id: https://svn.musicpd.org/mpd/trunk@7367 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-01 22:24:44 +00:00
Max Kellerman
e0be3aad20 assert dc.state == DECODE_STATE_STOP
During the decoder thread main loop, dc.state must be
DECODE_STATE_STOP.  Explicitly assigning it after the "dc.stop" check
is redundant.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7366 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-01 22:24:35 +00:00
Max Kellermann
3c3620b301 fix race condition in main_notify.c
The function wait_main_task() is racy: if the function
wakeup_via_cond() sees the mutex is locked just before
wait_main_task() executes pthread_cond_wait(), the main thread blocks
forever.

Work around this issue by adding a "pending" flag just like in my
notify.c code.  A standards-compliant solution should be implemented
later.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7365 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-17 03:05:23 +00:00
Max Kellermann
7c952c4f4b added ob_set_lazy()
In lazy mode (previously the default), outputBuffer.c only wakes up
the player when it was previously empty.  That caused a deadlock when
the player was waiting for buffered_before_play, since the decoder
wouldn't wake up the player when buffered_before_play was reached.  In
non-lazy mode, always wake up the player when a new chunk was decoded.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7364 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-15 05:57:22 +00:00
Max Kellermann
071c8f4ac7 use dc.current_song instead of pc.current_song
When we are in an input plugin, dc.current_song should already be
set.  Use it instead of pc.current_song.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7363 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-15 05:57:14 +00:00
Max Kellermann
119f457cff const pointers in decode.c
git-svn-id: https://svn.musicpd.org/mpd/trunk@7362 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-15 05:57:01 +00:00
Max Kellermann
d548deb45b const pointers in normalize.c
git-svn-id: https://svn.musicpd.org/mpd/trunk@7361 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-15 05:56:54 +00:00
Max Kellermann
f201f2c922 more const pointers in pcm_utils.[ch]
git-svn-id: https://svn.musicpd.org/mpd/trunk@7360 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-15 05:56:35 +00:00
Max Kellermann
df34beb98d fix XFADE_DISABLED=-1
git-svn-id: https://svn.musicpd.org/mpd/trunk@7359 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-15 05:56:18 +00:00
Eric Wong
b44506084e decode.c: make the crossfade state variable self-documenting
git-svn-id: https://svn.musicpd.org/mpd/trunk@7358 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-14 06:41:05 +00:00
Eric Wong
93fee6fc85 command.c: remove dead commented code
We have revision control for a reason :)

git-svn-id: https://svn.musicpd.org/mpd/trunk@7357 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-14 06:41:00 +00:00
Eric Wong
0f040a7030 Always compile ioops.h, since main_notify uses it now
git-svn-id: https://svn.musicpd.org/mpd/trunk@7356 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-13 18:04:02 +00:00
Eric Wong
412ce8bdc4 Make the OutputBuffer API more consistent
We had functions names varied between
outputBufferFoo, fooOutputBuffer, and output_buffer_foo

That was too confusing for my little brain to handle.
And the global variable was somehow named 'cb' instead of
the more obvious 'ob'...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7355 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-13 01:16:27 +00:00
Eric Wong
c1963ed483 Stop passing our single OutputBuffer object everywhere
All of our main singleton data structures are implicitly shared,
so there's no reason to keep passing them around and around in
the stack and making our internal API harder to deal with.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7354 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-13 01:16:15 +00:00
Eric Wong
dec6b1612e Stop passing our single DecoderControl object everywhere
This at least makes the argument list to a lot of our plugin
functions shorter and removes a good amount of line nois^W^Wcode,
hopefully making things easier to read and follow.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7353 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-13 01:16:03 +00:00
Eric Wong
98acfa8ac5 Get rid of PlayerControl inside the PlayerData struct
It actually increases our image size a small bit and may even
hurt performance a very small bit, but makes the code less
verbose and easier to manage.

I don't see a reason for mpd to ever support playing multiple
files at the same time (users can run multiple instances of mpd
if they really want to play Zaireeka, but that's such an edge
case it's not worth ever supporting in our code).

git-svn-id: https://svn.musicpd.org/mpd/trunk@7352 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-13 01:15:50 +00:00
Eric Wong
ae1335753a main_notify: just use cond_signal to wakeup, no need to trylock
pthread_cond_signal is a no-op if nothing is waiting on it

git-svn-id: https://svn.musicpd.org/mpd/trunk@7351 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-13 01:15:43 +00:00
Eric Wong
78370a9759 main_notify: use pthread_cond_signal instead of broadcast
signal is all we need since we only have one waiter and
likely faster

git-svn-id: https://svn.musicpd.org/mpd/trunk@7349 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 10:27:57 +00:00
Eric Wong
30bd8b2c0f Fix a deadlock after pause/next
Oops, forgot to unlock a mutex

git-svn-id: https://svn.musicpd.org/mpd/trunk@7348 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 10:27:53 +00:00
Eric Wong
baf9b94ecf Fix the problem of songs not advancing without client activity
The select() in the main event loop blocks now (saving us many
unnecessary wakeups).  This interacted badly with the threads
that were trying to wakeup the main task via
pthread_cond_signal() since the main task was not blocked
on a condition variable, but on select().

So now if we detect a need to wakeup the player, we write
to a pipe which select() is watching instead of blindly
calling pthread_cond_signal().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7347 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 09:46:11 +00:00
Eric Wong
804088f590 command.h: include sllist.h which defines struct strnode
git-svn-id: https://svn.musicpd.org/mpd/trunk@7346 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:27:09 +00:00
Max Kellermann
dec2a063cd const pointers in audioOutput.c
git-svn-id: https://svn.musicpd.org/mpd/trunk@7345 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:43 +00:00
Max Kellermann
b4ea6e52b2 const pointers in audio.c
git-svn-id: https://svn.musicpd.org/mpd/trunk@7344 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:39 +00:00
Max Kellermann
ac0ac9d4d8 flush after loop in sendDataToOutputBuffer()
Since tailChunk() automatically flushes full buffers, we do not have
to check this in every iteration of sendDataToOutputBuffer().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7343 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:34 +00:00
Max Kellermann
e4746b82c9 constant pointers in replayGain.c
git-svn-id: https://svn.musicpd.org/mpd/trunk@7342 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:28 +00:00
Max Kellermann
1308290c0d yet another migration to size_t
We can also get rid of one the two variables.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7341 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:22 +00:00
Max Kellermann
bc7e60cbcd check cb->stop in the while loop
Checking dc->stop in the while condition and again after the while
loop costs some CPU cycles we should save.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7340 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:18 +00:00
Max Kellermann
f0e78138d1 eliminate OutputBuffer.currentChunk
OutputBuffer.currentChunk contains redundant data: it is either -1
when there is no chunk which is currently being written, or it equals
"end".  If we always keep chunk[end] in a valid state, we can remove
OutputBuffer.currentChunk.

This patch may look a bit clumsy, especially flushOutputBuffer(), but
that will be fixed later with an major OutputBuffer API overhaul.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7339 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:13 +00:00
Max Kellermann
3105280f26 added output_buffer_expand()
output_buffer_expand() moves the cb->end to the new position (only its
current successor is allowed) and wakes up the player if is waiting
for the decoder.  This simplifies flushOutputBuffer().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7338 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:09 +00:00
Max Kellermann
5cfb1cf46e initialize all elements in initOutputBuffer()
The current OutputBuffer object is allocated statically, i.e. it is
zeroed.  To be safe for other cases in the future, also initialize the
other elements.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7337 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:04 +00:00