diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-04-12 04:08:00 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-04-12 04:08:00 +0000 |
commit | 9cf66d0e8a7875026d7009d5df331fabf614ac55 (patch) | |
tree | ee40e579af5fed033be317be4c5b2e18ec7020fe /src/inputPlugins | |
parent | d742fa6596099b963127b33e845f1c8485cc5840 (diff) | |
download | mpd-9cf66d0e8a7875026d7009d5df331fabf614ac55.tar.gz mpd-9cf66d0e8a7875026d7009d5df331fabf614ac55.tar.xz mpd-9cf66d0e8a7875026d7009d5df331fabf614ac55.zip |
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
Diffstat (limited to '')
-rw-r--r-- | src/inputPlugins/aac_plugin.c | 2 | ||||
-rw-r--r-- | src/inputPlugins/audiofile_plugin.c | 1 | ||||
-rw-r--r-- | src/inputPlugins/flac_plugin.c | 1 | ||||
-rw-r--r-- | src/inputPlugins/mod_plugin.c | 1 | ||||
-rw-r--r-- | src/inputPlugins/mp3_plugin.c | 4 | ||||
-rw-r--r-- | src/inputPlugins/mp4_plugin.c | 2 | ||||
-rw-r--r-- | src/inputPlugins/mpc_plugin.c | 1 | ||||
-rw-r--r-- | src/inputPlugins/oggflac_plugin.c | 1 | ||||
-rw-r--r-- | src/inputPlugins/oggvorbis_plugin.c | 1 | ||||
-rw-r--r-- | src/inputPlugins/wavpack_plugin.c | 1 |
10 files changed, 15 insertions, 0 deletions
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 0091b396e..de442acf7 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -400,6 +400,7 @@ static int aac_decode(OutputBuffer * cb, DecoderControl * dc, char *path) if (dc->seek) { dc->seekError = 1; dc->seek = 0; + decoder_wakeup_player(); } else if (dc->stop) { eof = 1; break; @@ -418,6 +419,7 @@ static int aac_decode(OutputBuffer * cb, DecoderControl * dc, char *path) if (dc->seek) { dc->seekError = 1; dc->seek = 0; + decoder_wakeup_player(); } return 0; diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c index 1c94a8589..33ea54df9 100644 --- a/src/inputPlugins/audiofile_plugin.c +++ b/src/inputPlugins/audiofile_plugin.c @@ -102,6 +102,7 @@ static int audiofile_decode(OutputBuffer * cb, DecoderControl * dc, char *path) dc->audioFormat.sampleRate; afSeekFrame(af_fp, AF_DEFAULT_TRACK, current); dc->seek = 0; + decoder_wakeup_player(); } ret = diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c index 7dab78922..23d61e805 100644 --- a/src/inputPlugins/flac_plugin.c +++ b/src/inputPlugins/flac_plugin.c @@ -394,6 +394,7 @@ static int flac_decode_internal(OutputBuffer * cb, DecoderControl * dc, } else dc->seekError = 1; dc->seek = 0; + decoder_wakeup_player(); } } if (!dc->stop) { diff --git a/src/inputPlugins/mod_plugin.c b/src/inputPlugins/mod_plugin.c index 22c364d70..25cedf04b 100644 --- a/src/inputPlugins/mod_plugin.c +++ b/src/inputPlugins/mod_plugin.c @@ -194,6 +194,7 @@ static int mod_decode(OutputBuffer * cb, DecoderControl * dc, char *path) if (dc->seek) { dc->seekError = 1; dc->seek = 0; + decoder_wakeup_player(); } if (dc->stop) diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index b008a1dd9..76d226b00 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -857,6 +857,7 @@ static int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc, clearOutputBuffer(cb); data->muteFrame = 0; dc->seek = 0; + decoder_wakeup_player(); } break; default: @@ -972,10 +973,12 @@ static int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc, dc->seekError = 1; data->muteFrame = 0; dc->seek = 0; + decoder_wakeup_player(); } } else if (dc->seek && !data->inStream->seekable) { dc->seek = 0; dc->seekError = 1; + decoder_wakeup_player(); } } @@ -1082,6 +1085,7 @@ static int mp3_decode(OutputBuffer * cb, DecoderControl * dc, if (dc->seek && data.muteFrame == MUTEFRAME_SEEK) { clearOutputBuffer(cb); dc->seek = 0; + decoder_wakeup_player(); } flushOutputBuffer(cb); diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c index 2e3dd18ae..0484e9993 100644 --- a/src/inputPlugins/mp4_plugin.c +++ b/src/inputPlugins/mp4_plugin.c @@ -221,6 +221,7 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc, clearOutputBuffer(cb); seeking = 0; dc->seek = 0; + decoder_wakeup_player(); } if (seeking) @@ -296,6 +297,7 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc, if (dc->seek && seeking) { clearOutputBuffer(cb); dc->seek = 0; + decoder_wakeup_player(); } flushOutputBuffer(cb); diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c index 49142aaed..9b6e862ff 100644 --- a/src/inputPlugins/mpc_plugin.c +++ b/src/inputPlugins/mpc_plugin.c @@ -194,6 +194,7 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, } else dc->seekError = 1; dc->seek = 0; + decoder_wakeup_player(); } vbrUpdateAcc = 0; diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c index 4e56a554a..6638362b6 100644 --- a/src/inputPlugins/oggflac_plugin.c +++ b/src/inputPlugins/oggflac_plugin.c @@ -370,6 +370,7 @@ static int oggflac_decode(OutputBuffer * cb, DecoderControl * dc, } else dc->seekError = 1; dc->seek = 0; + decoder_wakeup_player(); } } diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index 539dc55b7..8eb075336 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -285,6 +285,7 @@ static int oggvorbis_decode(OutputBuffer * cb, DecoderControl * dc, } else dc->seekError = 1; dc->seek = 0; + decoder_wakeup_player(); } ret = ov_read(&vf, chunk + chunkpos, OGG_CHUNK_SIZE - chunkpos, diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index e25b5099c..37dc4f3d0 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -192,6 +192,7 @@ static void wavpack_decode(OutputBuffer *cb, DecoderControl *dc, } dc->seek = 0; + decoder_wakeup_player(); } if (dc->stop) |