Commit Graph

249 Commits

Author SHA1 Message Date
Max Kellermann
17e9cc84c5 added decoder_seek_where() and decoder_seek_error()
Provide access to seeking for the decoder plugins; they have to know
where to seek, and they need a way to tell us that seeking has failed.
2008-08-26 08:27:07 +02:00
Max Kellermann
78c55e2432 added decoder_command_finished() to decoder_api.h
Some decoder commands are implemented in the decoder plugins, thus
they need to have an API call to signal that their current command has
been finished.  Let them use the new decoder_command_finished()
instead of the internal dc_command_finished().
2008-08-26 08:27:07 +02:00
Max Kellermann
817a68b2b2 added decoder_get_command()
Another big patch which hides internal mpd APIs from decoder plugins:
decoder plugins regularly poll dc->command; expose it with a
decoder_api.h function.
2008-08-26 08:27:07 +02:00
Max Kellermann
08bdb43bef moved InputPlugin to decoder_api.h
InputPlugin is the API which is implemented by a decoder plugin.  This
belongs to the public API/ABI, so move it to decoder_api.h.  It will
later be renamed to something like "decoder_plugin".
2008-08-26 08:27:06 +02:00
Max Kellermann
4a87f1e815 remove one indent level from audiofile plugin
Anonymous code blocks just to declare variables look ugly.  Move the
variable declarations up and disband the code block.
2008-08-26 08:27:06 +02:00
Max Kellermann
d186260016 use break instead of local variable "eof"
Similar to previous patch: eliminate one variable by using "break".
This also simplifies the code since we can remove one level of indent.
2008-08-26 08:27:06 +02:00
Max Kellermann
4c06624988 removed local variable "eof" because it is unused
"break" is so much easier than "eof=1; continue;", when "!eof" is the
loop condition.
2008-08-26 08:27:06 +02:00
Max Kellermann
ee3bbb5028 simplify several dc->command checks
Since we have merged dc->stop, dc->seek into one variable, we don't
have to check both conditions at a time; we can replace "!stop &&
!seek" with "none".
2008-08-26 08:27:06 +02:00
Max Kellermann
0d8b551c5a added parameter total_time to decoder_initialized()
Similar to the previous patch: pass total_time instead of manipulating
dc->totalTime directly.
2008-08-26 08:27:05 +02:00
Max Kellermann
4590a98f0e added audio_format parameter to decoder_initialized()
dc->audioFormat is set once by the decoder plugins before invoking
decoder_initialized(); hide dc->audioFormat and let the decoder pass
an AudioFormat pointer to decoder_initialized().
2008-08-26 08:27:05 +02:00
Max Kellermann
0d45870cea added decoder_clear() and decoder_flush()
We are now beginning to remove direct structure accesses from the
decoder plugins.  decoder_clear() and decoder_flush() mask two very
common buffer functions.
2008-08-26 08:27:05 +02:00
Max Kellermann
2a83ccdb8f added decoder_data()
Moved all of the player-waiting code to decoder_data(), to make
OutputBuffer more generic.
2008-08-26 08:27:05 +02:00
Max Kellermann
2bf7ec4f39 added decoder_initialized()
decoder_initialized() sets the state to DECODE_STATE_DECODE and wakes
up the player thread.  It is called by the decoder plugin after its
internal initialization is finished.  More arguments will be added
later to prevent direct accesses to the DecoderControl struct.
2008-08-26 08:27:04 +02:00
Max Kellermann
154aa496e8 added struct decoder
The decoder struct should later be made opaque to the decoder plugin,
because maintaining a stable struct ABI is quite difficult.  The ABI
should only consist of a small number of stable functions.
2008-08-26 08:27:04 +02:00
Max Kellermann
9e0f7dcd1a added dc_command_finished()
dc_command_finished() is invoked by the decoder thread when it has
finished a command (sent by the player thread).  It resets dc.command
and wakes up the player thread.  This combination was used at a lot of
places, and by introducing this function, the code will be more
readable.
2008-08-26 08:27:04 +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
Max Kellermann
b6909da758 clean up CPP includes
Include only headers which are really required.  This speeds up
compilation and helps detect cross-layer accesses.
2008-08-26 08:27:03 +02:00
Max Kellermann
a383f45117 enable -Wpointer-arith, -Wstrict-prototypes
Also enable -Wunused-parameter - this forces us to add the gcc
"unused" attribute to a lot of parameters (mostly library callback
functions), but it's worth it during code refactorizations.
2008-08-26 08:27:02 +02:00
Max Kellermann
c7d1ce07f3 don't call seekInputStream(0) if r==0
If nothing has been read from the input stream, we don't have to
rewind it.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7397 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:43:32 +00:00
Max Kellermann
7e99a0b0a9 eliminated local variable "to_read"
The variable "to_read" is never modified except in the last iteration
of the while loop.  This means the while condition will never become
false, as the body will break before that may be checked.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7396 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:43:27 +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
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 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
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
3919a87525 replaced assertion with check
During my tests, it happened that data->position>newPosition.  I have
not yet fully understood why this can happen; for now, replace this
with a run-time check.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7334 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:50 +00:00
Max Kellermann
a25a7624f0 multiply num_samples with bytes_per_channel
The patch "convert blocks until the buffer is full" did not update
data->chunk_length correctly: it added the number of samples, not the
number of bytes.  Multiply that with bytes_per_channel

git-svn-id: https://svn.musicpd.org/mpd/trunk@7332 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:40 +00:00
Max Kellermann
f4252ee795 missing num_channels check in previous patch
In the patch "special optimized case for 16bit stereo", the check for
"num_channels==2" was missing.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7331 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:34 +00:00
Max Kellermann
00fbd7bb4b special optimized case for 16bit stereo
Not having to loop for every sample byte (depending on a variable
unknown at compile time) saves a lot of CPU cycles.  We could consider
reimplementing this function with liboil...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7330 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:30 +00:00
Max Kellermann
3db2b98718 read num_channels once
Read frame->header.channels once, and pass only this integer to
flac_convert().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7329 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:25 +00:00
Max Kellermann
a91f2a1f05 assume the buffer is empty in flacWrite()
flacWrite() is the only function which sets data->chunk_length.  If we
flush the buffer before we return, we can assume that it is always
empty upon entering flacWrite().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7328 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:19 +00:00
Max Kellermann
ca1090f93b convert blocks until the buffer is full
Move the inner loop which converts samples to flac_convert().  There
it is isolated and easier to optimize.  This function does not have to
worry about buffer boundaries; the caller (i.e. flacWrite())
calculates how much is left and is responsible for flushing.  That
saves a lot of superfluous range checks within the loop.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7327 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:13 +00:00
Max Kellermann
0673c9a84d calculate bytes_per_channel, check for buffer flush once
Check for flushing the chunk buffer only once per sample, before
iterating over channels and bytes.  This saves another 5% CPU cycles.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7326 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:06 +00:00
Max Kellermann
51e9044098 don't calculate bytes per sample within the loop
AudioFormat.bits is volatile, and to read it, 3 pointers had to be
deferenced.  Calculate this value once.  This speeds up this function
by 5%.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7325 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:59 +00:00
Max Kellermann
96eb0119cc use unsigned integers and size_t in the flac plugin
git-svn-id: https://svn.musicpd.org/mpd/trunk@7324 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:55 +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
Eric Wong
f275a1a1ab Fix a few more warnings from -Wshadow
git-svn-id: https://svn.musicpd.org/mpd/trunk@7300 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:32 +00:00
Max Kellermann
f7e97c9a89 constant pointers
There were some const pointers missing in the previous const-cleanup
patch.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7290 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:30 +00:00
Max Kellermann
05c41a80ed fix parameter types in the faad calls
libfaad wants uint32_t pointers.  Passing a long pointer is bugged on
amd64.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7289 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:24 +00:00
Max Kellermann
2ede0780f6 fix compilation error in wavpack plugin
The patch "Start using song pointers in core data structures" removed
dc->utf8url, and the adaption for wavpack_plugin.c was missing.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7288 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:16 +00:00
Max Kellermann
a5aa5a0258 yet more unsigned integers
git-svn-id: https://svn.musicpd.org/mpd/trunk@7287 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:10 +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
51f5bf932c use unsigned integers in the flac plugin
The counter variables c_samp and c_chan begin at zero and can never be
negative.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7228 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:06:39 +00:00
Max Kellermann
4dc709d04e removed unused variable
The local variable d_samp is initialized, but never actually used.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7227 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:06:28 +00:00
Eric Wong
d78ddd1e50 wavpack_plugin: cleanups after the last commit
* malloc() => xmalloc() for error checking
* strncpy() replaced with memcpy(),
memcpy appears perfectly safe here and mpd
does not ever use strncpy() (see r4491)

git-svn-id: https://svn.musicpd.org/mpd/trunk@7211 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:34 +00:00
Laszlo Ashin
ad0d350f28 WavPack improvements
This patch does the following:
-enables WVC support for streams as well,
-improves MPD inputStream <=> WavPack stream connector,
-fixes two compile warnings (which were caused by MPD API change).

Mantis #1660 <http://musicpd.org/mantis/view.php?id=1660>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7210 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:30 +00:00
Eric Wong
7c560d047d audiofile_plugin: fix nasty long lines introduced in previous commit
Terminals are 80 columns and that's a hard limit, no exceptions

git-svn-id: https://svn.musicpd.org/mpd/trunk@7207 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:17 +00:00