Commit Graph

75 Commits

Author SHA1 Message Date
Max Kellermann
ca68b1c80a CPP include cleanup
Include only headers which are really used.
2008-10-08 10:49:26 +02:00
Max Kellermann
e2c8b960de moved code to pc_init(), dc_init() 2008-08-26 08:45:14 +02:00
Max Kellermann
5e51fa020d renamed player.c to player_control.c
Give player.c a better name, meaning that the code is used to control
the player thread.
2008-08-26 08:44:38 +02:00
Max Kellermann
56cdce6946 renamed decode.h to decoder_control.h 2008-08-26 08:44:19 +02:00
Max Kellermann
4255bba0f7 moved global variable "pc" to player.h
This is the last of the three variables.  Now we don't need
playerData.h anymore in most sources.
2008-08-26 08:41:05 +02:00
Max Kellermann
a94845ee00 moved global variable "ob" to outputBuffer.h
This releases several include file dependencies.  As a side effect,
"CHUNK_SIZE" isn't defined by decoder_api.h anymore, so we have to
define it directly in the plugins which need it.  It just isn't worth
it to add it to the decoder plugin API.
2008-08-26 08:41:05 +02:00
Max Kellermann
1c03c721ea moved variable "dc" to decode.h
Now that "dc" is available here, we don't have to pass it to
decoder_is_idle() and decoder_is_starting() anymore.
2008-08-26 08:40:47 +02:00
Max Kellermann
efde884a13 added PlayerControl.command
PlayerControl.command replaces the old attributes play, stop, pause,
closeAudio, lockQueue, unlockQueue, seek.  The main thread waits for
each command synchronously, so there can only be one command enabled
at a time anyway.
2008-08-26 08:27:07 +02:00
Max Kellermann
5df6ff8d22 added OutputBuffer.notify
OutputBuffer should be a more generic low-level library, without
dependencies to the other headers.  This patch adds the field
"notify", which is used to signal the player thread.  It is passed in
the constructor, and removes the need to compile with the decode.h
header.
2008-08-26 08:27:05 +02:00
Max Kellermann
8d3942e0c3 merged start, stop, seek into DecoderControl.command
Much of the existing code queries all three variables sequentially.
Since only one of them can be set at a time, this can be optimized and
unified by merging all of them into one enum variable.  Later, the
"command" checks can be expressed in a "switch" statement.
2008-08-26 08:27:04 +02: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 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
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
Max Kellermann
c89b358c8a clean up CPP includes
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
2008-04-12 04:19:26 +00:00
Max Kellermann
f2cdac6ee7 added output_buffer_free()
To do proper cleanup before exiting, we have to provide a destructor
for OutputBuffer.  One day, valgrind will not complain about memory
leaks!

git-svn-id: https://svn.musicpd.org/mpd/trunk@7315 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:38 +00:00
Max Kellermann
e20b71ed63 remove buffered_chunks, use cb->size
Second patch to make OutputBuffer self-contained: since OutputBuffer
now knows its own size, we do not need the global variable
"buffered_chunks" anymore.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7311 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:12 +00:00
Max Kellermann
e9e557c8d1 pass buffered_chunks to initOutputBuffer()
Try to make OutputBuffer self-contained, without depending on a global
variable.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7310 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:04 +00:00
Max Kellermann
b2819e12e7 make playerData_pd static
git-svn-id: https://svn.musicpd.org/mpd/trunk@7309 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:17:55 +00:00
Max Kellermann
288a7087f6 allocate playerData_pd from heap instead of shm
git-svn-id: https://svn.musicpd.org/mpd/trunk@7308 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:17:46 +00:00
Max Kellermann
70ba525144 don't allocate pd.auddioDeviceStates from shm
git-svn-id: https://svn.musicpd.org/mpd/trunk@7306 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:17:12 +00:00
Max Kellermann
78f606078e let initOutputBuffer() allocate memory
This is the first patch in a series which removes the shared memory,
and moves all the playerData objects into the normal libc heap.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7304 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:56 +00:00
Max Kellermann
b7ac3fab46 use the notify API in the player
git-svn-id: https://svn.musicpd.org/mpd/trunk@7282 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:38 +00:00
Max Kellermann
701cf6884c use the notify API in the decoder
git-svn-id: https://svn.musicpd.org/mpd/trunk@7281 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:32 +00:00
Max Kellermann
74910df0f3 added struct OutputBufferChunk
To make access to OutputBuffer easier, move everything which belongs
to a chunk into its own structure, namely OutputBufferChunk.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7269 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:24 +00:00
Eric Wong
efa4642356 Start using song pointers in core data structures
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-12 04:08:29 +00:00
Eric Wong
45ebb851f4 Drop metadata updates from HTTP for now (input HTTP, and shout)
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-12 04:08:12 +00:00
Eric Wong
9cf66d0e8a Initial cut of fork() => pthreads() for decoder and player
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-12 04:08:00 +00:00
Max Kellermann
1b6cf29937 unsigned integers in playerData.[ch]
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-12 04:07:01 +00:00
Max Kellermann
1910df96a3 moved code to initOutputBuffer()
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-26 10:38:12 +00:00
Eric Wong
cb8f1af3bd Cleanup #includes of standard system headers and put them in one place
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
2008-01-03 07:29:49 +00:00
Eric Wong
b79f6b882a Merge branches/ew r7104
thread-safety work in preparation for rewrite to use pthreads

Expect no regressions against trunk (r7078), possibly minor
performance improvements in update (due to fewer heap
allocations), but increased stack usage.

Applied the following patches:

* maxpath_str for reentrancy (temporary fix, reverted)
* path: start working on thread-safe variants of these methods
* Re-entrancy work on path/character-set conversions
* directory.c: exploreDirectory() use reentrant functions here
* directory/update: more use of reentrant functions + cleanups
* string_toupper: a strdup-less version of strDupToUpper
* get_song_url: a static-variable-free version of getSongUrl()
* Use reentrant/thread-safe get_song_url everywhere
* replace rmp2amp with the reentrant version, rmp2amp_r
* Get rid of the non-reentrant/non-thread-safe rpp2app, too.
* buffer2array: assert strdup() returns a usable value in unit tests
* replace utf8ToFsCharset and fsCharsetToUtf8 with thread-safe variants
* fix storing playlists w/o absolute paths
* parent_path(), a reentrant version of parentPath()
* parentPath => parent_path for reentrancy and thread-safety
* allow "make test" to automatically run embedded unit tests
* remove convStrDup() and maxpath_str()
* use MPD_PATH_MAX everywhere instead of MAXPATHLEN
* path: get rid of appendSlash, pfx_path and just use pfx_dir
* get_song_url: fix the ability to play songs in the top-level music_directory

git-svn-id: https://svn.musicpd.org/mpd/trunk@7106 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-28 02:56:25 +00:00
J. Alexander Treuman
01faa6f4e3 Set a flag if we've sent the player process SIGSTOP so that we know not to
wait for it to complete an action which it never will.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6488 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-06-04 23:14:38 +00:00
J. Alexander Treuman
89eca9eebc Don't kill the player process (and effectively the decode process) when
completely stopped.  Instead, send them SIGSTOP to pause the process until
they're needed again.  Then send them SIGCONT instead of re-spawning them.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6485 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-06-04 22:29:55 +00:00
J. Alexander Treuman
6d7e0eb166 Tell the player process (and thus also the decode process) to quit when
playback is stopped completely.  This means the player process will no
longer have to wake up 100 times per second to see if it's been told to
start playing (the main process will just spawn a new player process when
it needs to).  On the downside, this means an extra pair of forks() and the
re-initializing of the player and decode processes each time playback is
restarted.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6446 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-06-01 18:10:13 +00:00
J. Alexander Treuman
b9b39849d8 Increasing default buffer_before_play from 0% to 10%.
git-svn-id: https://svn.musicpd.org/mpd/trunk@6290 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-27 13:12:02 +00:00
J. Alexander Treuman
bba444524e Changing all calls to ERROR() followed by exit(EXIT_FAILURE) with a single
call to FATAL().

git-svn-id: https://svn.musicpd.org/mpd/trunk@6276 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-26 18:15:54 +00:00
J. Alexander Treuman
2814b7cfc6 Reverting to the full lsr API. Turns out the simple API needs all of the
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-24 21:15:37 +00:00
Avuton Olrich
a061da8fb5 The massive copyright update
git-svn-id: https://svn.musicpd.org/mpd/trunk@5834 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-04-05 03:22:33 +00:00
Eric Wong
9caade4eb1 fix a few warnings on 64-bit machines
size_t is bigger than int on most 64-bit machines, so cast
size_t to long when passing them to printf-like functions.

Ideally we'd use %z, but many compilers don't support it.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4656 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-18 07:02:54 +00:00
Eric Wong
e5df85db15 Several bugfixes during exit found by valgrind
First, make sure we call finishPlaylist() before
closeMp3Directory() since the latter will free non-SONG_TYPE_URL
songs in playlist, which causes an invalid read when we try to
look for SONG_TYPE_URL songs to free in finishPlaylist.

Secondly, make sure our children have all exited before freeing
the playerData.  If we do not, slowly-delivered signals can
trigger a race condition in the signal handlers of the decode
and player processes which rely on getPlayerData.  To avoid
waitpid-ing too long (or at all), move the freePlayerData() call
farther down in main() (this won't affect anything else)
to give the OS a better chance to deliver signals and finish running
sig handlers for terminated children.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4640 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-14 23:31:08 +00:00
Warren Dukes
31de97a42b merge changes from mpd-tree:
-use tree for tagTracker
-eliminate the master process

git-svn-id: https://svn.musicpd.org/mpd/trunk@4571 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-06 06:40:11 +00:00
Eric Wong
b0965c317b audio: get rid of the myAudioDevicesEnabled array
It just made things more confusing.  We'll just store
the states in playerData_pd->audioDevicesStates and be
done with it (it's a unsigned byte now).

git-svn-id: https://svn.musicpd.org/mpd/trunk@4514 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-01 10:07:12 +00:00
Eric Wong
c22a53d373 audio: remove AUDIO_MAX_DEVICES limit
Some people have more than 8 devices (the old limit).  It's
pretty easy to support as many as our hardware and OS allows
so we might as well.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4513 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-01 10:07:07 +00:00
Eric Wong
2532bc36d2 playerData: move player_pid into the main playerData structure
No point in doing all that extra work for one variable...

git-svn-id: https://svn.musicpd.org/mpd/trunk@4511 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-01 04:18:48 +00:00
Eric Wong
5aca21a502 Several fixes uncovered with -pedantic
playerData.c:
proper error checking

directory.c:
properly check myFgets() for errors
(it returns NULL on error)

inputPlugins/mp3_plugin.c
get rid of commas at the end of enums

interface.c:
we weren't using long long, so strtoll isn't needed
get rid of void-pointer arithmetic

sllist.c:
get rid of void-pointer arithmetic

compress.c:
get rid of C++ comments, some compilers don't accept them

Note that I personally like void pointer arithmetic, but some
ancient compilers don't support them :(

git-svn-id: https://svn.musicpd.org/mpd/trunk@4510 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-01 04:18:41 +00:00
Avuton Olrich
29a25b9933 Add mpd-indent.sh
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-20 16:02:40 +00:00
Eric Wong
368034e199 sparse: replace 0 (integer) usage with NULL where appropriate
Probably pedantic, but yes, might as well in case we run into
strange platforms where NULL is something strange.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4380 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-17 00:15:52 +00:00