Commit Graph

2344 Commits

Author SHA1 Message Date
Eric Wong
74b34f7b61 directory: fix leak introduced with threaded update
Use freeList() instead of free() to free all elements in
the list.
2008-09-23 22:38:39 +02:00
Eric Wong
260e1a9037 Remove EINTR checking for open(2)
open(2) should only interrupt on "slow" devices, afaik...

[mk: still using fopen()]
2008-09-23 22:38:36 +02:00
Eric Wong
5cc5c37856 directory: don't leak file handles if we get a corrupt db 2008-09-23 22:37:40 +02:00
Eric Wong
28d39948d7 songvec: remove songvec_prune
Any pruned files will be noticed during update and pruned
from the live database, so this inefficient function can
go away and never come back.
2008-09-23 22:37:33 +02:00
Eric Wong
3f0ae13c4b directory: update do its work inside a thread
A lot of the preparation was needed (and done in previous
months) in making update thread-safe, but here it is.

This was the first thing I made work inside a thread when I
started mpd-uclinux many years ago, and also the last thing I've
done in mainline mpd to work inside a thread, go figure.
2008-09-23 22:37:18 +02:00
Max Kellermann
0f0ac43b8f directory: use enum update_return for return values II
Converted some more functions and their callers to enum update_return.
2008-09-23 22:36:00 +02:00
Eric Wong
986c2f134d directory: use enum update_return for return values
This way we avoid having to document -1, 0, 1
2008-09-23 20:49:05 +02:00
Eric Wong
cfc2dd3e94 Don't try to prune unless we're updating
Pruning is very expensive and we won't need it in the future
anyways.  This brings startup back to previous speeds (before
songvec changes).
2008-09-23 20:48:51 +02:00
Eric Wong
cce2f93de7 workaround race condition on updates with broken signal blocking
pthreads with our existing signal blocking/handling is broken,
for now just sleep a bit in the child to prevent the CHLD handler
from being called too early.  Also, improve error reporting when
handling SIGCHLD by storing the status to be called in the main
task (which can be logged, since we can't do logging inside the
sig handler).
2008-09-23 20:48:44 +02:00
Eric Wong
0bec1d3807 Replace SongList with struct songvec
Our linked-list implementation is wasteful and the
SongList isn't modified enough to benefit from being a linked
list.  So use a more compact array of song pointers which
saves ~200K on a library with ~9K songs (on x86-32).
2008-09-23 20:48:39 +02:00
Eric Wong
afe6ce7210 directory: remove unused updateMp3Directory() function
It hasn't been used in many years

  commit 3a89afdd80
  Author: Warren Dukes <warren.dukes@gmail.com>
  Date:   Sat Nov 20 20:28:32 2004 +0000

      remove --update-db option

      (SVN r2719)
2008-09-23 20:48:33 +02:00
Eric Wong
27fad52c6b start using prefixcmp()
LOC reduction and less noise makes things easier for
tired old folks to follow.
2008-09-23 20:48:12 +02:00
Eric Wong
f5df13f853 Add prefixcmp() (stol^H^H^H^Hborrowed from git)
This allows us to avoid the nasty repetition in strncmp(foo,
bar, strlen(foo)).  We'll miss out on the compiler optimizing
strlen() into sizeof() - 1 for string literals for this; but we
don't use this it for performance-critical functions anyways...
2008-09-23 20:48:08 +02:00
Eric Wong
15b25ad174 volume: oops, only #include <alloca.h> if OSS is enabled 2008-09-23 20:48:04 +02:00
Eric Wong
9f441f2538 oss: avoid heap allocations when configuring mixer
Noticed-by: Courtney Cavin
2008-09-23 20:47:53 +02:00
Eric Wong
d095d52ed4 Directory: don't allocate stat information dynamically
This should save a few thousand ops.  Not worth it to malloc
for such a small (3-words on 32-bit ARM and x86) structures.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
2008-09-23 20:47:45 +02:00
Eric Wong
3263dbe517 mp3: fix long line, I can't read past 80 cols 2008-09-23 20:47:40 +02:00
Max Kellermann
7613688575 main_notify: removed assertion in wakeup_main_task()
It is legal to call wakeup_main_task() from within the main thread,
e.g. from within a signal handler.  Remove the assertion.
2008-09-23 20:47:32 +02:00
Max Kellermann
1db88364bb main_notify: use init_async_pipe()
Remove duplicated code.
2008-09-23 20:47:31 +02:00
Max Kellermann
913028a780 mp3: fix buffer overflow when max_frames is too large
The function decodeFirstFrame() allocates memory based on data from
the mp3 header.  This can make the buffer size allocation overflow, or
lead to a DoS attack with a very large buffer.  Cap this buffer at 8
million frames, which should really be enough for reasonable files.
2008-09-17 22:30:34 +02:00
Max Kellermann
ef0e2fdc1b client: check expired after client_process_line()
The assertion on "!client_is_expired(client)" was wrong, because
writing the command response may cause the client to become expired.
Replace that assertion with a check.
2008-09-17 22:02:13 +02:00
Terry
79a14c9a10 mp4: fix potential integer overflow bug in the mp4_decode() function
A crafted mp4 file could cause an integer overflow in mp4_decode
function in src/inputPlugins/mp4_plugin.c.  mp4ff_num_samples()
function returns some tainted value. sizeof(float) * numSamples is an
integer overflow operation if numSamples is too huge, so xmalloc will
allocate a small memory region.  I constructe a mp4 file, and use
faad2 to open the file. mp4ff_num_samples() returns -1. So I think mpd
bears from the same problem.
2008-09-12 17:06:04 +02:00
Max Kellermann
89c8b19a8c shout: don't write empty buffers
Add a check to write_page() which checks if there is actually data.
Don't bother to call shout_send() if there is not.
2008-09-12 16:42:14 +02:00
Max Kellermann
42f6177199 shout: removed clear_shout_buffer()
The function is trivial, without a benefit.  Also don't initialize
buf.data[0], this is not a null terminated string.
2008-09-12 16:41:22 +02:00
Max Kellermann
265b8fffb2 shout: make the shout_buffer static
Since the buffer size is known at compile time, we can save an
indirection by declaring it as a char array instead of a pointer.
That saves an extra allocation, and we can calculate with the
compile-time constant sizeof(data) instead of the attribute "max_len".
2008-09-12 16:41:20 +02:00
Max Kellermann
ebd194998a shout: constant plugin declarations
Declare both shout plugins "const", since they will never change, once
initialized at compile time.
2008-09-12 16:39:53 +02:00
Max Kellermann
d9f170b5db shout: static encoder plugin list
Shout encoder plugins are known at compile time.  There is no reason
to use a complex data structure as "List" to manage them at runtime -
just put the pointers into a static array.
2008-09-12 16:39:51 +02:00
Max Kellermann
a84de9b010 shout: removed typedefs on structs and plugin methods
Don't typedef the structs at all.  It is easier to forward-declare
this way.

Don't typedef methods.  They are used exactly once, a few lines below.
2008-09-12 16:38:54 +02:00
Eric Wollesen
5f8eebd122 shout: added mp3 encoder
[mk: moved this patch after "Refactor and cleanup of shout Ogg and MP3
audio outputs".  The original commit message follows, although it is
outdated:]

Creation of shout_mp3 audio output plugin. Basically I just copied the
existing shout plugin and replaced ogg with lame. Uses lame for mp3
encoding. Next step is to pull common functionality out of each shout
plugin and share it between them.

Configuration options for "shout_mp3" are the same as for "shout".
2008-09-12 16:05:23 +02:00
Eric Wollesen
4970c42c86 shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:

Both Ogg and MP3 use the "shout" audio output plugin.  The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.

Configuration for an Ogg stream doesn't change.  For an MP3 stream,
configuration is the same as Ogg, with two exceptions.  First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details.  Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.

I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.

To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs.  This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.

The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures.  Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.)  I suspect the performance impact
is negligible.

As for metadata, I'm pretty sure they'll both work.  I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds.  It seemed to work fine.  Of course,
if something does break, I'll be glad to fix it.

Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.

[mk: moved the MP3 patch after this one.  Splitted this patch into
several parts; the others were already applied before this one.  Fixed
a bunch GCC warnings and wrong whitespace modifications.  Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
Eric Wollesen
43ee3c3b36 shout: send shout metadata
Support sending metadata to a shout server using shout_metadata_new()
and shout_metadata_add().  The Ogg Vorbis encoder does not support
this currently.

[mk: this patch was separated from Eric's patch "Refactor and cleanup
of shout Ogg and MP3 audio outputs", I added a description]
2008-09-12 16:00:01 +02:00
Max Kellermann
1333c39244 shout: added struct _ogg_vorbis_data
Preparing the merge of Eric Wollesen's patch "Refactor and cleanup of
shout Ogg and MP3 audio outputs": we declare one of the struct types
here, to make the merge smoother.
2008-09-12 15:59:55 +02:00
Eric Wollesen
f482f83eb8 shout: added shout_buffer
The Ogg encoder is slightly less optimal under this configuration.  It
used to send shout data directly out of its ogg_page structures.  Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin
(see audioOutput_shout_ogg.c, line 77.)  I suspect the performance
impact is negligible.

[mk: this patch and its description was separated from Eric's patch
"Refactor and cleanup of shout Ogg and MP3 audio outputs"]
2008-09-12 15:57:43 +02:00
Max Kellermann
fcac05a207 shout: moved code to audioOutput_shout_ogg.c
Begin dividing audioOutput_shout.c: move everything OGG Vorbis related
to audioOutput_shout_ogg.c.  The header audioOutput_shout.h has to
keep its dependency on vorbis/vorbisenc.h, because it needs the vorbis
encoder types.

For this patch, we have to export several internal functions with
generic names to the ABI; these will be removed later when the encoder
plugin patches are merged.
2008-09-12 15:02:57 +02:00
Max Kellermann
7d3ca9c1ff shout: moved declarations to audioOutput_shout.h
Prepare the split of the shout plugin into multiple sources: move
all important declarations to audioOutput_shout.h.
2008-09-12 14:59:53 +02:00
Max Kellermann
b0884ddd81 shout: removed commented code
Remove unused code which is in comments.  Remove that comment about
"stolen code", since the plugin has changed much, and it isn't obvious
which parts are derived.
2008-09-12 14:58:42 +02:00
Max Kellermann
0eb4038dcb shout: no CamelCase 2008-09-12 14:01:45 +02:00
Max Kellermann
85d952c58b output: copy reqAudioFormat to outAudioFormat only if not yet open
If the output device is already open, it may have modified
outAudioFormat; in this case, outAudioFormat is still valid, and does
not need an overwrite.
2008-09-11 07:50:20 +02:00
Max Kellermann
420c879dd6 output: don't initialize inAudioFormat, outAudioFormat
As long as the device isn't open, both attributes are not used.  Since
they will both be initialized in audio_output_open(), we do not need
the initialization in audio_output_init().
2008-09-11 07:50:11 +02:00
Max Kellermann
19fe134b38 shout: use reqAudioFormat instead of outAudioFormat
In the plugin's init() function, outAudioFormat is simply a copy of
reqAudioFormat.  Use reqAudioFormat instead of outAudioFormat here.
2008-09-11 07:49:52 +02:00
Max Kellermann
544c13cc89 shout: copy the audio_format, instead of taking a pointer
Storing pointers to immutable audio_format structs isn't worth it,
because the struct itself isn't much larger than the pointer.  Since
the shout plugin requires the user to configure a fixed audio format,
we can simply copy it in myShout_initDriver().
2008-09-11 07:49:51 +02:00
Max Kellermann
3aa4564b56 output: removed audio_output.sameInAndOutFormats
Eliminate sameInAndOutFormats and check with audio_format_equals()
each time it this information is needed.  Another 4 bytes saved.
2008-09-11 07:48:30 +02:00
Max Kellermann
56cf54e880 output: removed audio_output.convertAudioFormat
Instead of checking convertAudioFormat, we can simply check if
reqAudioFormat is defined.  This saves 4 bytes in the struct.
2008-09-11 07:47:28 +02:00
Max Kellermann
a751011e8c audio: removed commented code
We have git..
2008-09-10 11:47:28 +02:00
Max Kellermann
52ed06cbd8 audio: added assertions 2008-09-10 11:46:54 +02:00
Max Kellermann
688298e265 audio: make audio_configFormat a static variable
Save one allocation, since the whole audio_format struct is nearly the
same size as the pointer to it.  Check audio_format_defined(af)
instead of af!=NULL.
2008-09-10 11:44:06 +02:00
Max Kellermann
5d0a8ce3af audio: don't free uninitialized audio_buffer
free(NULL) isn't explicitly forbidden, but isn't exactly good style.
Check the rare case that the audio buffer isn't initialized yet in
closeAudioDevice().  In this case, we also don't have to call
flushAudioBuffer().
2008-09-10 11:44:02 +02:00
Max Kellermann
8d1801c59d audio: added function audio_buffer_resize()
To make openAudioDevice() smaller and more readable, move code to a
static function.  Also don't use realloc(), since the old value of the
buffer isn't needed anymore, saving a memcpy().
2008-09-10 11:43:56 +02:00
Max Kellermann
cdbb9627a7 audio: moved static variables into struct audio_buffer
There are too many static variables in audio.c - organize all
properties of the audio buffer in a struct.  The current audio format
is also a property of the buffer, since it describes the buffer's
data format.
2008-09-10 11:43:49 +02:00
Max Kellermann
9f16a34d76 audio: don't allow isCurrentAudioFormat(NULL)
Passing NULL to this function doesn't make sense, and complicates its
implementation.  The one caller which might pass NULL should rather
check this.
2008-09-10 11:43:40 +02:00
Max Kellermann
a53047af7d audio: removed isAudioDeviceOpen()
The function isAudioDeviceOpen() is never used.
2008-09-10 11:43:29 +02:00
Max Kellermann
d92543698c audio_format: added audio_format_clear() and audio_format_defined()
audio_format_clear() sets an audio_format struct to an cleared
(undefined) state, which is both faster and smaller than memset(0).
audio_format_defined() checks if the audio_format struct actually has
a defined value (i.e. non-zero).  Both can be used to avoid pointers
to audio_format, replacing the "NULL" value with an "undefined"
audio_format.
2008-09-10 11:43:27 +02:00
Max Kellermann
9ceadb0561 client: simplified client_read()
Remove one comparison by changing branch order.
2008-09-10 11:43:09 +02:00
Max Kellermann
1bb154098d client: client_input_received() returns 0
Since the caller chain doesn't care about the return value (except for
COMMAND_RETURN_KILL, COMMAND_RETURN_CLOSE), just return 0 if there is
nothing special.  This saves one local variable initialization, and
one access to it.

Also remove one unreachable "return 1" from client_read().
2008-09-10 11:42:30 +02:00
Max Kellermann
48191d5661 client: check for COMMAND_RETURN_CLOSE
Don't close the client within client_process_line(), return
COMMAND_RETURN_CLOSE instead.  This is the signal for the caller chain
to actually close it.  This makes dealing with the client pointer a
lot safer, since the caller always knows whether it is still valid.
2008-09-10 11:42:26 +02:00
Max Kellermann
a580f5fe68 client: renamed local variable "selret" to "ret"
It's easier to reuse the variable if it has a more generic name.
2008-09-10 11:41:34 +02:00
Max Kellermann
a49b1d145e client: moved CLOSE/KILL check after client_process_line()
Don't update client data if it is going to be closed anyway.
2008-09-10 11:41:33 +02:00
Max Kellermann
be9212ba84 audio: moved cmpAudioFormat() to audio_format.h
Rename it to audio_format_equals() and return "true" if they are
equal.
2008-09-09 10:05:15 +02:00
Max Kellermann
7f1cccb3ea audio: replaced copyAudioFormat() with simple assignment
The "!src" check in copyAudioFormat() used to hide bugs - one should
never pass NULL to it.  There is one caller which might pass NULL, add
a check in this caller.

Instead of doing mempcy(), we can simply assign the structures, which
looks more natural.
2008-09-09 10:04:42 +02:00
Max Kellermann
f9316fbbbe output: renamed the functions in output_control.c
Getting rid of CamcelCase, again.
2008-09-09 10:03:24 +02:00
Max Kellermann
e2c916e6ca output: moved code from audioOutput.c to output_control.c
Similar to decoder_control.c, output_control.c will provide functions
for controlling the output thread (which will be implemented later).
2008-09-09 10:02:34 +02:00
Max Kellermann
755d55075d output: renamed method names
No CamelCase.  Also don't declare typedefs for the methods.
2008-09-09 10:01:34 +02:00
Max Kellermann
40a9961bcd output: removed keepAudioOutputAlive() declaration
This function is declared, but is neither used nor implemented.
2008-09-09 10:01:31 +02:00
Max Kellermann
182746b95c timer: constant pointers
The audio_format argument to timer_new() should be constant, because
it is not modified.  The same is true for ShoutData.audioFormat.
2008-09-09 10:01:29 +02:00
Eric Wong
35494158c8 storedPlaylist: correctly expand path when writing
Otherwise we'd be writing to whatever directory that mpd is
running in.
2008-09-09 09:59:34 +02:00
Eric Wong
5c81b716e2 alsa: use blocking instead of non-blocking write
The way we used non-blocking mode was HORRIBLE.

It was non-blocking to ALSA, but we end up blocking in a busy
loop that does absolutely NOTHING but retry.  We don't check
for playback cancellation (like we do in decoders) or anything.

This is seriously broken and I can imagine it affects people on
fast CPUs more because we do asynchronous output buffering and
our ALSA device will always have data ready.
2008-09-09 09:03:08 +02:00
Eric Wong
37489b1f97 alsa: snd_pcm_sw_params_set_xfer_align is deprecated
Lets not use deprecated functions. It's apparently
possible to not care about the sw_params stuff at all!
2008-09-08 20:44:22 +02:00
Eric Wong
d0ab3a31ac alsa: only run snd_config_update_free_global once atexit
This is safer than the patch in
  http://www.musicpd.org/mantis/view.php?id=1542
with multiple audio outputs enabled.

Sadly, I only noticed that patch/problem when I googled for
"snd_config_update_free_global"
2008-09-08 20:43:59 +02:00
Eric Wong
7d0c32b450 alsa: move bitformat reading code out of the way 2008-09-08 20:42:51 +02:00
Eric Wong
67c642c935 alsa: avoid unnecessary heap usage if we don't set a device name 2008-09-08 20:42:39 +02:00
Eric Wong
f1f1104b2c alsa: get rid of the needless canPause flag
We never use it for anything anyways as we release the device
entirely on pause.
2008-09-08 20:42:35 +02:00
Eric Wong
fa246e02be alsa: capitalize "ALSA" consistently in messages
That's the name of this project.
2008-09-08 20:42:34 +02:00
Eric Wong
7bd98c08ce alsa: optimistically try resuming from suspend
Apparently snd_pcm_hw_params_can_resume() can return false even
though my hardware does in fact support resuming.  So stop
carrying that value in the canResume flag and just try to resume
when we're in the suspended state; falling back to
snd_pcm_prepare only if resuming fails.  libao does something
similar on resume, too.

While we're at it, use the E() macro which will enable us to
have better error reporting.

[mk: remove the E() macro stuff]
2008-09-08 20:31:05 +02:00
Max Kellermann
da1e858458 strset: fix duplicate values
Due to a minor typo, the string set had duplicate values, because
strset_add() didn't check the base slot properly.
2008-09-08 12:07:08 +02:00
Max Kellermann
f0e64ceb48 use strset.h instead of tagTracker.h
With a large music database, the linear string collection in
tagTracker.c becomes very slow.  We implemented that in a
quick'n'dirty fashion when we removed tree.c, and now we rewrite it
using the fast hashed string set.
2008-09-08 11:47:57 +02:00
Max Kellermann
2b8040b425 added string set library
"struct strset" is a hashed string set: you can add strings to this
library, and it stores them as a set of unique strings.  You can get
the size of the set, and you can enumerate through all values.

This will be used to replace the linear tagTracker library.
2008-09-08 11:46:04 +02:00
Max Kellermann
3f6fe915eb output: const plugin structures
Since the plugin struct is never modified, we should store it in
constant locations.
2008-09-08 11:43:38 +02:00
Max Kellermann
be046b25a4 output: static audio_output_plugin list as array
Instead of having to register each output plugin, store them
statically in an array.  This eliminates the need for the List library
here, and saves some small allocations during startup.
2008-09-08 11:43:13 +02:00
Max Kellermann
a0103dd05c output: replace audio_output.*Func with audio_output.plugin
Instead of copying all that stuff from the audio output plugin to the
audio output structure, store a pointer to the plugin.
2008-09-07 22:42:51 +02:00
Max Kellermann
3b09c54b67 output: renamed typedef AudioOutput to struct audio_output
Also rename AudioOutputPlugin to struct audio_output_plugin, and use
forward declarations to reduce include dependencies.
2008-09-07 22:41:22 +02:00
Max Kellermann
bed2a49fe9 output: added output_api.h
Just like decoder_api.h, output_api.h provides the audio output API
which is used by the plugins.
2008-09-07 22:41:17 +02:00
Max Kellermann
dc7c6bd14d pack the struct audio_format
Due to clumsy layout, the audio_format struct took 12 bytes.  Move the
"channels" to the end, so it can be merged into the same 32 bit slot
as "bits", which reduces the struct size to 8 bytes.
2008-09-07 19:20:01 +02:00
Max Kellermann
f1dd9c209c audio_format: converted typedef AudioFormat to struct audio_format
Get rid of CamelCase, and don't use a typedef, so we can
forward-declare it, and unclutter the include dependencies.
2008-09-07 19:19:55 +02:00
Max Kellermann
bd81fd8b0c playlist: return -1 after assert(0)
print_playlist_result() had an assert(0) at the end, in case there was
an invalid result value.  With NDEBUG, this resulted in a function not
returning a value - add a dummy "return -1" at the end to keep gcc
quiet.
2008-09-07 19:19:48 +02:00
Max Kellermann
3553ed2f9b playlist: replaced song_id_exists() with song_id_to_position()
Since all callers of song_id_exists() will map it to a song position
after the check, introduce a new function called song_id_to_position()
which performs both the check and the map lookup, including nice
assertions.
2008-09-07 19:19:41 +02:00
Max Kellermann
1ce5f4d75b command: use client_[gs]et_permission()
Don't pass a pointer to client->permission to processCommand(), better
let the code in command.c use the new permission getter/setter
functions.
2008-09-07 19:17:25 +02:00
Max Kellermann
2835e37684 client: added client_[gs]et_permission()
The code in command.c shouldn't mess with a pointer to
client->permission.  Provide an API for accessing this value.
2008-09-07 19:16:34 +02:00
Max Kellermann
bf6994d8e3 command: don't pass permission as pointer where appropriate
Some functions don't want to modify a client's permission set.  Pass
the permissions to them by value, not by reference.
2008-09-07 19:15:45 +02:00
Eric Wong
18fc10a926 audio_format: volatile removal
volatile provides absolutely no guarantee thread-safety in SMP
environments.  volatile was designed to access memory locations
in peripheral hardware directly; not for SMP.  If volatile is
needed to work properly on SMP, then it is only hiding subtle
bugs.

volatile only prevents the /compiler/ from making optimizations
when accessing variables.  CPUs do their own optimizations at
runtime so it cannot guarantee registers of CPUs are flushed
to memory cache-coherent access on different CPUs.

Furthermore, the thread-communication via condition variables
between threads sharing audio formats already results in memory
barriers.
2008-09-07 19:14:50 +02:00
Eric Wong
a5f68b3cfc tag: oops, of course items is now ** and not *
Gah, it seems like doing sizeof here either way is error
prone.  Too easy to leave out a '*' character we can
forget.
2008-09-07 19:14:47 +02:00
Eric Wong
3c4de5b560 tag: lock all accesses to tag_pool
The tag pool is a shared global resource that is infrequently
modified.  However, it can occasionally be modified by several
threads, especially by the metadata_pipe for streaming metadata
(both reading/writing).

The bulk tag_item pool is NOT locked as currently only the
update thread uses it.
2008-09-07 19:14:45 +02:00
Eric Wong
194c8c3c0f tag: introduce handy items_size() function
Trying to read or remember
  "tag->numOfItems * sizeof(*tag->items)"
requires too much thinking and mental effort on my part.

Also, favor "sizeof(struct mpd_tag)" over "sizeof(*tag->items)"
because the former is easier to read and follow, even though
the latter is easier to modify if the items member changes
to a different type.
2008-09-07 19:14:43 +02:00
Max Kellermann
4dd9d4b2fd fix -Wcast-qual -Wwrite-strings warnings
The previous patch enabled these warnings.  In Eric's branch, they
were worked around with a generic deconst_ptr() function.  There are
several places where we can add "const" to pointers, and in others,
libraries want non-const strings.  In the latter, convert string
literals to "static char[]" variables - this takes the same space, and
seems safer than deconsting a string literal.
2008-09-07 19:14:39 +02:00
Max Kellermann
86d261bdb5 removed fdprintf() and client_print()
All callers of fdprintf() have been converted to client_printf() or
fprintf(); it is time to remove this clumsy hack now.  We can also
remove client_print() which took a file descriptor as parameter.
2008-09-07 14:08:37 +02:00
Max Kellermann
322e908893 client: removed client_get_fd()
Now that we have removed all invocations of client_get_fd(), we can
safely remove this transitional function.  All access to the file
descriptor is now hidden behind the interface declared in client.h.
2008-09-07 14:05:02 +02:00
Max Kellermann
4d8438e63d audio: don't pass "fd" to printAudioDevices()
Pass the client struct instead.
2008-09-07 14:04:16 +02:00
Max Kellermann
a6c5928c75 stats: don't pass "fd" to printStats()
Pass the client struct instead of the raw file descriptor.
2008-09-07 14:02:57 +02:00
Max Kellermann
93e6d4c3ad playlist: don't pass "fd" to showPlaylist(), playlistChangesPosId()
Pass the client struct instead of the raw file descriptor.
2008-09-07 14:02:52 +02:00
Max Kellermann
709ec6fa39 playlist: added playlist_save()
The shared code in showPlaylist() isn't worth it, because we aim to
remove fdprintf().  Duplicate this small function, and enable stdio
buffering for saved playlists.
2008-09-07 14:02:43 +02:00
Max Kellermann
438b56f0ba ls: don't pass "fd" to lsPlaylists(), printRemoteUrlHandlers()
Pass the client struct instead of the raw file descriptor.
2008-09-07 14:02:40 +02:00
Max Kellermann
4665f2bf32 tag: don't pass "fd" to printVisitedInTagTracker()
Pass the client struct instead of the raw file descriptor.
2008-09-07 13:57:58 +02:00
Max Kellermann
94293149b1 command: concatenate strings at compile time
String literals (including those defined in CPP macros) can be
concatenated at compile time.  This saves some CPU cycles in
vsnprintf() at run time.
2008-09-07 13:57:43 +02:00
Max Kellermann
b332e1cbc8 command: removed commandError()
commandError() has been superseded by command_error(), and is not
being used anymore.  Remove it.
2008-09-07 13:57:37 +02:00
Max Kellermann
f59986fad5 playlist: pass struct client to loadPlaylist()
The function loadPlaylist() wants to report incremental errors to the
client, for this reason we cannot remove its protocol dependency right
now.  Instead, make it use the client struct instead of the raw file
descriptor.
2008-09-07 13:57:26 +02:00
Max Kellermann
dc8b64fdef pass "struct client" to dbUtils.c, song.c, tag_print.c
Don't pass the raw file descriptor around.  This migration patch is
rather large, because all of the sources have inter dependencies - we
have to change all of them at the same time.
2008-09-07 13:53:55 +02:00
Max Kellermann
5609a1fcd0 command: pass struct client to all commands
Pass the client struct to CommandHandlerFunction and
CommandListHandlerFunction.  Most commands cannot take real advantage
of that yet, since most of them still work with the raw file
descriptor.
2008-09-07 13:52:48 +02:00
Max Kellermann
d2543f03f5 command: pass struct client to getCommandEntryAnd...()
Instead of passing the file descriptor, pass the client struct to
getCommandEntryAndCheckArgcAndPermission().
2008-09-07 13:52:36 +02:00
Max Kellermann
54371add13 command: added command_success() and command_error()
These two functions take a client struct instead of the file
descriptor.  We will now begin passing the client struct around
instead of a raw file descriptor (which needed a linear lookup in the
client list to be useful).
2008-09-07 13:51:59 +02:00
Max Kellermann
4ddc0a48e2 audio: don't pass "fd" to {en,dis}ableAudioDevice()
No protocol code in the audio output library.
2008-09-07 13:51:50 +02:00
Max Kellermann
f7e414d934 volume: don't pass "fd" to changeVolumeLevel()
The "volume" library shouldn't talk to the client.  Move error
handling to command.c.
2008-09-07 13:50:16 +02:00
Max Kellermann
8e3c40f032 directory: don't pass "fd" to updateInit()
Again, move error handling to command.c.
2008-09-07 13:50:06 +02:00
Max Kellermann
17b6491bcf directory: printDirectoryInfo() does not call commandError()
Move another ocurrence of error handling over to command.c.
2008-09-07 13:49:01 +02:00
Max Kellermann
f320c9fa1d directory: don't pass fd to traverseAllIn()
This patch continues the work of the previous patch: don't pass a file
descriptor at all to traverseAllIn().  Since this fd was only used to
report "directory not found" errors, we can easily move that check to
the caller.  This is a great relief, since it removes the dependency
on a client connection from a lot of enumeration functions.
2008-09-07 13:48:37 +02:00
Max Kellermann
528be8a0a9 directory: don't pass fd to traverseAllIn() callbacks
Database traversal should be generic, and not bound to a client
connection.  This is the first step: no file descriptor for the
callback functions forEachSong() and forEachDir().  If a callback
needs the file descriptor, it has to be passed in the void*data
pointer somehow; some callbacks might need a new struct for passing
more than one parameter.  This might look a bit cumbersome right now,
but our goal is to have a clean API.
2008-09-07 13:48:24 +02:00
Max Kellermann
d8ef33b710 playlist: PlaylistInfo() does not call commandError()
Continuing the effort of removing protocol specific calls from the
core libraries: let the command.c code call commandError() based on
PlaylistInfo's return value.
2008-09-07 13:44:20 +02:00
Max Kellermann
a8b225f947 playlist: don't pass "fd" to storedPlaylist.c functions
Return an "enum playlist_result" value instead of calling
commandError() in storedPlaylist.c.
2008-09-07 13:44:12 +02:00
Max Kellermann
8d2830b3f9 playlist: don't pass "fd" to playlist.c functions
The playlist library shouldn't talk to the client if possible.
Introduce the "enum playlist_result" type which the caller
(i.e. command.c) may use to generate an error message.
2008-09-07 13:39:31 +02:00
Max Kellermann
20feb0cbba playlist: showPlaylist() and shufflePlaylist() cannot fail
Make them both return void.
2008-09-07 13:39:19 +02:00
Max Kellermann
e1bf96672e playlist: moved "repeat" and "random" value checks to command.c
Client's input values should be validated by the command
implementation, and the core libraries shouldn't talk to the client
directly if possible.  Thus, setPlaylistRepeatStatus() and
setPlaylistRandomStatus() don't get the file descriptor, and cannot
fail (return void).
2008-09-07 13:38:59 +02:00
Max Kellermann
d1df71ebbc playlist: fix FILE* leak in appendSongToStoredPlaylistByPath()
When an error occurs after the file has been opened, the function will
never close the FILE object.
2008-09-07 13:37:33 +02:00
Max Kellermann
54c8e3daaf playlist: replaced run-time check with assertion
The "fspath" argument of writeStoredPlaylistToPath() must never be
NULL.  There should be an assertion on that, instead of a run-time
check.
2008-09-07 13:37:20 +02:00
Max Kellermann
dc353eca80 playlist: added is_valid_playlist_name()
The function valid_playlist_name() checks the name, but it insists on
reporting an eventual error to the client.  The new function
is_valid_playlist_name() is more generic: it just returns a boolean,
and does not care what the caller will use it for.  The old function
valid_playlist_name() will be removed later.
2008-09-07 13:37:04 +02:00
Max Kellermann
59efed3e8e tag: added buffered versions of the tag_print.c code
Currently, when the tag cache is being serialized to hard disk, the
stdio buffer is flushed before every song, because tag_print.c
performs unbuffered writes on the raw file descriptor.  Unfortunately,
the fdprintf() API allows buffered I/O only for a client connection by
looking up the client pointer owning the file descriptor - for stdio,
this is not possible.  To re-enable proper stdio buffering, we have to
duplicate the tag_print.c code without fprintf() instead of our custom
fdprintf() hack.  Add this duplicated code to tag_save.c.
2008-09-07 13:36:05 +02:00
Max Kellermann
75aa8dad4c song: moved code to song_print.c, song_save.c
Move everything which dumps song information (via tag_print.c) to a
separate source file.  song_print.c gets code which writes song data
to the client; song_save.c is responsible for serializing songs from
the tag cache.
2008-09-07 13:35:01 +02:00
Max Kellermann
386c303121 tag: moved code to tag_print.c
Move everything which dumps a tag to a file descriptor to tag_print.c.
This relaxes dependencies and splits the code into smaller parts.
2008-09-07 13:28:01 +02:00
Max Kellermann
f73319c048 client: added client_printf()
Based on client_puts(), client_printf() is the successor of
fdprintf().  As soon as all fdprintf() callers have been rewritten to
use client_printf(), we can remove fdprintf().
2008-09-07 13:25:54 +02:00
Max Kellermann
33aec0d673 client: added client_write() and client_puts()
client_write() writes a buffer to the client and buffers it if
required.  client_puts() does the same for a C string.  The next patch
will add more tools which will replace fdprintf() later.
2008-09-07 13:24:51 +02:00
Max Kellermann
a34e1d2b84 include cleanup
As usual, include only headers which are really needed.
2008-09-06 20:28:31 +02:00
Eric Wong
092bdf3d32 tag: fix segfault on update
clearMpdTag could be called on a tag that was still in a
tag_begin_add transaction before tag_end_add is called.  This
was causing free() to attempt to operate on bulk.items; which is
un-free()-able.  Now instead we unmark the bulk.busy to avoid
committing the tags to the heap only to be immediately freed.

Additionally, we need to remember to call tag_end_add() when
a song is updated before we NULL song->tag to avoid tripping
an assertion the next time tag_begin_add() is called.
2008-09-06 15:31:55 +02:00
Max Kellermann
6146d4f5bb client: don't check FD_ISSET(client->fd) on expired client
client->fd becomes -1 when the client expires.  Don't use FD_ISSET()
with this expired client; doing so would cause a crash due to SIGBUS.
2008-09-06 15:31:55 +02:00
Max Kellermann
77b1671662 client: removed assert(client->fd)>=0
Since client->fd==-1 has become our "expired" flag, it may already be
-1 when client_close() is called.  Don't assert that it is still
non-negative, and call client_set_expired() instead.
2008-09-06 15:31:55 +02:00
Max Kellermann
35c0b84f08 dbUtils, playlist, directory: pass constant pointers
The usual bunch of const pointer conversions.
2008-09-06 15:28:31 +02:00
Max Kellermann
d38d2bc353 tag: optimize tag_dup(), copy item references
Don't call tag_pool_get_item() for duplicating tags, just increase the
item's reference counter instead.
2008-08-29 15:04:49 +02:00
Max Kellermann
d8ad109e10 oggflac: fix GCC warnings
Fix lots of "unused parameter" warnings in the OggFLAC decoder
plugin.  Not sure if anybody uses it anymore, since newer libflac
obsoletes it.
2008-08-29 15:03:09 +02:00
Max Kellermann
01f9684f70 tag: fix the shout and oggflac plugins
During the tag library refactoring, the shout plugin was disabled, and
I forgot about adapting it to the new API.  Apply the same fixes to
the oggflac decoder plugin.
2008-08-29 15:02:49 +02:00
Max Kellermann
37d77caa3c const pointers
Yet another patch which converts pointer arguments to "const".
2008-08-29 14:48:39 +02:00
Max Kellermann
5bd5551630 tag: static directory name
While parsing the tag cache, don't allocate the directory name from
the heap, but copy it into a buffer on the stack.  This reduces heap
fragmentation by 1%.
2008-08-29 09:39:12 +02:00
Max Kellermann
1aa3457346 tag: try not to reallocate tag.items in every add() call
If many tag_items are added at once while the tag cache is being
loaded, manage these items in a static fixed list, instead of
reallocating the list with every newly created item.  This reduces
heap fragmentation.

Massif results again:

 mk before:  total 12,837,632; useful 10,626,383; extra 2,211,249
 mk now:     total 12,736,720; useful 10,626,383; extra 2,110,337

The "useful" value is the same since this patch only changes the way
we allocate the same amount of memory, but heap fragmentation was
reduced by 5%.
2008-08-29 09:39:08 +02:00
Max Kellermann
031522060a song: don't export newNullSong()
The function newNullSong() is only used internally in song.c.
2008-08-29 09:39:07 +02:00
Max Kellermann
a208d654b3 tag: try not to duplicate the input string
Try to detect if the string needs Latin1-UTF8 conversion, or
whitespace cleanup.  If not, we don't need to allocate temporary
memory, leading to decreased heap fragmentation.
2008-08-29 09:39:04 +02:00
Max Kellermann
9352fc9e66 tag: pass length to fix_utf8()
Same as the previous patch, prepare the function fix_utf8() this time.
2008-08-29 09:39:01 +02:00
Max Kellermann
43c389b961 added "length" parameter to validUtf8String()
At several places, we create temporary copies of non-null-terminated
strings, just to use them in functions like validUtf8String().  We can
save this temporary allocation and avoid heap fragmentation if we
add a length parameter instead of expecting a null-terminated string.
2008-08-29 09:38:58 +02:00
Max Kellermann
92b757674e assert value!=NULL in fix_utf8()
We must never pass value==NULL to fix_utf().  Replace the run-time
check with an assertion.
2008-08-29 09:38:56 +02:00
Max Kellermann
f99fe80811 tag: converted macro fixUtf8() to an inline function
Since the inline function cannot modify its caller's variables (which
is a good thing for code readability), the new string pointer is the
return value.  The resulting binary should be the same as with the
macro.
2008-08-29 09:38:54 +02:00
Max Kellermann
c855415c73 tag: added a pool for tag items
The new source tag_pool.c manages a pool of reference counted tag_item
objects.  This is used to merge tag items of the same type and value,
saving lots of memory.  Formerly, only the value itself was pooled,
wasting memory for all the pointers and tag_item structs.

The following results were measured with massif.  Started MPD on
amd64, typed "mpc", no song being played.  My music database contains
35k tagged songs.  The results are what massif reports as "peak".

 0.13.2:     total 14,131,392; useful 11,408,972; extra 2,722,420
 eric:       total 18,370,696; useful 15,648,182; extra 2,722,514
 mk f34f694: total 15,833,952; useful 13,111,470; extra 2,722,482
 mk now:     total 12,837,632; useful 10,626,383; extra 2,211,249

This patch set saves 20% memory, and does a good job in reducing heap
fragmentation.
2008-08-29 09:38:37 +02:00
Max Kellermann
e5a7879892 tag: converted tag_item.value to a char array
The value is stored in the same memory allocation as the tag_item
struct; this saves memory because we do not store the value pointer
anymore.  Also remove the getTagItemString()/removeTagItemString()
dummies.
2008-08-29 09:38:33 +02:00
Max Kellermann
b731bbe93a removed tree.c
This patch makes MPD consume much more memory because string pooling
is disabled, but it prepares the next bunch of patches.  Replace the
code in tagTracker.c with naive algorithms without the tree code.  For
now, this should do; later we should find better algorithms,
especially for getNumberOfTagItems(), which has become wasteful with
temporary memory.
2008-08-29 09:38:31 +02:00
Max Kellermann
ad0e09b2db tag: converted MpdTag.items to a pointer list
This prepares the following patches, which aim to reduce MPD's memory
usage: we plan to share tag_item instances, instead of just their
values.
2008-08-29 09:38:29 +02:00
Max Kellermann
6f72fe3ecf tag: moved code to tag_id3.c
The ID3 code uses only the public tag API, but is otherwise
unrelated.  Move it to a separate source file.
2008-08-29 09:38:27 +02:00
Max Kellermann
055f4a41c5 wavpack: tag_new() cannot fail
Since tag_new() uses xmalloc(), it cannot fail - if we're really out
of memory, the process will abort.
2008-08-29 09:38:25 +02:00
Max Kellermann
5e1feb8fa3 tag: converted tag_add_item() to an inline function 2008-08-29 09:38:24 +02:00
Max Kellermann
91502cd71e tag: renamed functions, no CamelCase 2008-08-29 09:38:21 +02:00
Max Kellermann
d0556dc983 tag: renamed MpdTag and MpdTagItem to struct tag, struct mpd_tag_item
Getting rid of CamelCase; not having typedefs also allows us to
forward-declare the structures.
2008-08-29 09:38:11 +02:00
Max Kellermann
f42de62aa2 added xfree() which takes a const pointer
Unfortunately, the C standard postulates that the argument to free()
must be non-const.  This does not makes sense, and virtually prevents
every pointer which must be freed at some time to be non-const.  Use
the deconst hack (sorry for that) to allow us to free constant
pointers.
2008-08-29 09:38:08 +02:00
Max Kellermann
8811c0e059 export the function client_is_expired()
Instead of passing the pointer to the "expired" flag to
processListOfCommands(), this function should use the client API to
check this flag.  We can now remove the "global_expired" hack
introduced recently.
2008-08-29 09:37:11 +02:00
Max Kellermann
8b1b82b363 client: pass the client struct to processCommand()
Start exporting the client struct as an opaque struct.  For now, pass
it only to processCommand() and processListOfCommands(), and provide a
function to extract the socket handle.  Later, we will propagate the
pointer to all command implementations, and of course to
client_print() etc.
2008-08-29 09:36:42 +02:00
Max Kellermann
2c8aa8efde client: reorder function declarations
Change the order of function declarations in client.h, to make it well
arranged and readable.
2008-08-29 09:36:40 +02:00
Max Kellermann
e743d71b89 client: check "expired" after command execution
The old code tried to write a response to the client, without even
checking if it was already closed.  Now that we have added more
assertions, these may fail...  perform the "expired" check earlier.
2008-08-29 09:36:40 +02:00
Max Kellermann
76ecc30243 client: added global "expired" flag
Patch bdeb8e14 ("client: moved "expired" accesses into inline
function") was created under the wrong assumption that
processListOfCommands() could modify the expired flag, which is not
the case.  Although "expired" is a non-const pointer,
processListOfCommands() just reads it, using it as the break condition
in a "while" loop.  I will address this issue with a better overall
solution, but for now provide a pointer to a global "expired" flag.
2008-08-29 09:36:38 +02:00
Max Kellermann
12bcba8b89 pass constant pointers
And again, convert arguments to const.
2008-08-29 09:01:53 +02:00
Max Kellermann
d8a8fa63b4 client: removed superfluous assertion
client_defer_output() was modified so that it can create the
deferred_send list.  With this patch, the assertion on
"deferred_send!=NULL" has become invalid.  Remove it.
2008-08-29 06:17:54 +02:00
Eric Wong
7858081eda log.c: thread-safety for warning log
I'm really no fan of the warning log, it's too complex
for how little it gets used; but fixing it is another
problem.
2008-08-28 20:40:26 +02:00
Max Kellermann
08c9de7b68 client: more assertions 2008-08-28 20:23:22 +02:00
Max Kellermann
4e17ab11a8 client: replace "expired" flag with fd==-1
Why waste 4 bytes for a flag which we can hide in another variable.
2008-08-28 20:20:10 +02:00
Max Kellermann
bdeb8e148e client: moved "expired" accesses into inline function
Hiding this flag allows us later to remove it easily.
2008-08-28 20:20:10 +02:00
Max Kellermann
e0fd63ecf8 moved code to sockaddr_to_tmp_string()
Unclutter the client_new() constructor by moving unrelated complex
code into a separate function.
2008-08-28 20:20:10 +02:00
Max Kellermann
34735fab66 client: no while loop in client_manager_io()
The last patch removed the "continue" directive, and now the while
loop is without function.  Remove it.  Also make client_manager_io()
return 0.
2008-08-28 20:20:10 +02:00
Max Kellermann
f6a7dd2b45 client: select() errors are fatal
Previously, when select() failed, we assumed that there was an invalid
file descriptor in one of the client structs.  Thus we tried select()
one by one.  This is bogus, because we should never have invalid file
descriptors.  Remove it, and make select() errors fatal.
2008-08-28 20:20:10 +02:00
Max Kellermann
32bb19d03f client: use client_defer_output() in client_write()
Eliminate duplicated code, call client_defer_output() which we
splitted from client_write_output() earlier.
2008-08-28 20:20:04 +02:00
Max Kellermann
709b795e4a moved code to client_write()
Move the second part of client_write_output() into a separate
function.
2008-08-28 20:03:58 +02:00
Max Kellermann
4516bd117c client: client_defer_output() can create the first defer buffer
client_defer_output() was designed to add new buffers to an existing
deferred_send buffer.  Tweak it and allow it to create a new buffer
list.
2008-08-28 20:03:56 +02:00
Max Kellermann
20f06162dd client: return early on error in client_defer_output()
Exit the function when an error occurs, and move the rest of the
following code one indent level left.
2008-08-28 20:03:54 +02:00
Max Kellermann
7774cd2774 client: moved code to client_defer_output()
Split the large function client_write_output() into two parts; this is
the first code moving patch.
2008-08-28 20:03:51 +02:00
Max Kellermann
4448b17e2e don't free client resources except in client_close()
All of the client's resources are freed in client_close().  It is
enough to set the "expired" flag, no need to duplicate lots of
destruction code again and again.
2008-08-28 20:03:49 +02:00
Max Kellermann
61443c13e6 client: allocate clients dynamically
Due to the large buffers in the client struct, the static client array
eats several megabytes of RAM with a maximum of only 10 clients.  Stop
this waste and allocate each client struct from the heap.
2008-08-28 20:03:48 +02:00
Max Kellermann
a091c148e6 client: added function client_by_fd()
The code becomes less complex and more readable when we move this
linear search into a separate mini function.
2008-08-28 20:03:06 +02:00
Max Kellermann
d15e1e09a2 client: return early in client_new()
This saves one level of indent.
2008-08-28 20:03:03 +02:00
Max Kellermann
c0197c58ba client: renamed all public functions
Functions which operate on the whole client list are prefixed with
"client_manager_", and functions which handle just one client just get
"client_".
2008-08-28 20:03:02 +02:00
Max Kellermann
6d18e00099 client: renamed internal functions and variables
Rename all static functions, variables and macros which have
"interface" in their name to something nicer prefixed with "client_".
2008-08-28 20:02:59 +02:00
Max Kellermann
fe03cb9549 client: renamed Interface to struct client
Second patch: rename the internal struct name.  We will eventually
export this type as an opaque forward-declared struct later, so we
can pass a struct pointer instead of a file descriptor, which would
save us an expensive linear lookup.
2008-08-28 20:02:58 +02:00
Max Kellermann
deb29e0884 renamed interface.c to client.c
I don't believe "interface" is a good name for something like
"connection by a client to MPD", let's call it "client".  This is the
first patch in the series which changes the name, beginning with the
file name.
2008-08-28 20:02:43 +02:00
Max Kellermann
9340e291f0 imported list.h from the Linux kernel sources
linux/list.h is a nice doubly linked list library - it is lightweight
and powerful at the same time.  It will be useful later, when we begin
to allocate client structures dynamically.  Import it, and strip out
all the stuff which we are not going to use.
2008-08-28 20:02:20 +02:00
Max Kellermann
bc1c8835c6 const pointers
The usual bunch of pointer arguments which should be const.
2008-08-28 20:02:17 +02:00
Max Kellermann
801c71ed1c unsigned integers and size_t
Use "unsigned int" whenever negative values are not meaningful.  Use
size_t whenever we are going to describe buffer sizes.
2008-08-28 20:02:16 +02:00
Max Kellermann
1560a70b01 include cleanup
Only include headers which are really needed.
2008-08-28 20:01:08 +02:00
Max Kellermann
b7861868cf protect locate.h from double inclusion 2008-08-28 20:01:08 +02:00
Max Kellermann
f34f694ec3 moved player_command_finished() to player_thread.c 2008-08-26 08:45:15 +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
b616dff77d no commandError() in playerSeek()
We should avoid having protocol specific code in player.c.  Just
return success or failure, and let the caller send the error code to
the MPD client.
2008-08-26 08:44:34 +02:00
Max Kellermann
bf4af19f54 don't initialize "i" if we overwrite it anyway 2008-08-26 08:44:33 +02:00
Max Kellermann
a2b24462e8 renamed decoderInit() to decoder_thread_start() 2008-08-26 08:44:29 +02:00
Max Kellermann
56cdce6946 renamed decode.h to decoder_control.h 2008-08-26 08:44:19 +02:00
Max Kellermann
dff8c6450b renamed decode.c to decoder_thread.c
It should be obvious in which thread or context a function is being
executed at runtime.  The code which was left in decode.c is for the
decoder thread itself; give the file a better name.
2008-08-26 08:44:12 +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
15c9352bb6 moved enum decoder_command to decoder_api.h
The decoder plugins need this type, so export it in the public API.
This allows is to remove "decode.h" from "decoder_api.h", uncluttering
the API namespace some more.
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
9521c92f66 player_thread: removed decode(), renamed decodeParent()
decode() is a trivial wrapper for decodeParent().  Merge both and
rename them to do_play().
2008-08-26 08:29:37 +02:00
Max Kellermann
70904adf18 hide DecoderControl accesses in inline functions
Unfortunately, we have to pass the DecoderControl pointer to these
inline functions, because the global variable "dc" may not be
available here.  This will be fixed later.
2008-08-26 08:29:35 +02:00
Max Kellermann
a1ce999978 check for decoder error before state!=START
When dc->error!=NOERROR, we do not need to check state!=START.
Simplify the checks by moving the error check to the top.
2008-08-26 08:27:18 +02:00
Max Kellermann
c6035ea332 don't reset dc->command in quitDecode()
The decoder thread is responsible for resetting dc->command after a
command was executed.  As a consequence, we can assume that
dc->command is already NONE after decoder_stop().
2008-08-26 08:27:18 +02:00
Max Kellermann
8a4970f863 added decoder_control.c
The source "decoder_control.c" provides an API for controlling the
decoder.  This replaces various direct accesses to the DecoderControl
struct.
2008-08-26 08:27:18 +02:00
Max Kellermann
7d3429a6d8 removed the "queue" parameter from syncPlaylistWithQueue()
There is only one caller which passes "true", so we can move the
queueNextSongInPlaylist() invocation there.
2008-08-26 08:27:18 +02:00
Max Kellermann
a9f0d85115 merge the playlist lock functions into clearPlayerQueue()
There is no unlocked caller of clearPlayerQueue(), and the functions
lockPlaylistInteraction() and unlockPlaylistInteraction() are trivial
- merge them.
2008-08-26 08:27:17 +02:00
Max Kellermann
2a06e2dafa use switch/case in syncPlaylistWithQueue() 2008-08-26 08:27:17 +02:00
Max Kellermann
110cef6fda don't call playerStop() before playerPlay()
Since playerPlay() already calls playerStop(), we can remove its
invocation of playerStop() from playPlaylistOrderNumber().

We can also make playerStop a static function.
2008-08-26 08:27:17 +02:00
Max Kellermann
7125fdc4f2 assert locked/unlocked in queue lock functions
There are no nested queue locks in mpd, thus replace the locked checks
in playerQueueLock(), playerQueueUnlock() with assertions.
2008-08-26 08:27:17 +02:00
Max Kellermann
f168695699 don't unlock player queue in playerStop(), playerWait()
There is no caller of these two functions which locks the player
queue; replace the playerQueueUnlock() call with an assertion.
2008-08-26 08:27:17 +02:00
Max Kellermann
113c1c0af5 queueSong() cannot fail
All (indirect) callers of queueSong() ensure that the queue state is
BLANK, so there is no need to check it in queueSong() again.  As a
side effect, queueSong() cannot fail anymore, and can return void.
Also, playlist_queueError and all its error handling can go away.
2008-08-26 08:27:17 +02:00
Max Kellermann
b94af79134 fix a comment regarding the player queue 2008-08-26 08:27:17 +02:00
Max Kellermann
4613115bec document the PLAYER_QUEUE_ constants 2008-08-26 08:27:17 +02:00
Max Kellermann
55377fbd9f added enum player_queue_state 2008-08-26 08:27:16 +02:00
Max Kellermann
ae00330285 rewrote playerKill()
playerKill() was marked as deprecated, but it seems like a good idea
to do proper cleanup in all threads (e.g. for usable valgrind
results).  Introduce the command "EXIT" which makes the player thread
exit cleanly.
2008-08-26 08:27:16 +02:00
Max Kellermann
92d9797b8c player: don't call STOP before CLOSE_AUDIO
playerWait() stops the player thread (twice!) and closes the output
device.  It should be well enough to just send CLOSE_AUDIO, without
STOP.

This requires a tiny change to the player thread code: make it break
when CLOSE_AUDIO is sent.
2008-08-26 08:27:16 +02:00
Max Kellermann
cff923b9d8 playlist: eliminate unused fd parameters
Again, remove file descriptor parameters, which are not actually
used.  These functions can also be converted to return void.
2008-08-26 08:27:16 +02:00
Max Kellermann
3db333b5a4 player: no "fd" and no return value
Most player*() functions do not actually use the file descriptor, and
always return 0 (success).  Eliminate them to get a leaner interface.
2008-08-26 08:27:16 +02:00
Max Kellermann
6df980a996 flac: decoder command means EOF
It was possible for the decoder thread to go into an endless loop
(flac and oggflac decoders): when a "STOP" command arrived, the Read()
callback would return 0, but the EOF() callback returned false.  Fix:
when decoder_get_command()!=NONE, return EOF==true.
2008-08-26 08:27:16 +02:00
Max Kellermann
8a5109483d made "sample_size" static const
sample_size is a variable which is computed at compile time.  Declare
it "static const", so the compiler can optimize it away.
2008-08-26 08:27:16 +02:00
Max Kellermann
e056ff2b02 moved jack configuration to the JackData struct
Storing local configuration in global (static) variables is obviously
a bad idea.  Move all those variables into the JackData struct,
including the locks.
2008-08-26 08:27:16 +02:00
Max Kellermann
479d02da0e jack: removed unused macros 2008-08-26 08:27:15 +02:00
Max Kellermann
edd7e2f94e jack: don't set audioOutput->data=NULL
There is only one caller of freeJackData() left: jack_finishDriver().
This function is called by the mpd core, and is called exactly once
for every successful jack_initDriver().  We do not need to clear
audioOutput->data, since this variable is invalidated anyway.
2008-08-26 08:27:15 +02:00
Max Kellermann
806a9f02a1 jack: initialize JackData in jack_initDriver()
Over the lifetime of the jack AudioOutput object, we want a single
valid JackData object, so we can persistently store data there
(configuration etc.).  Allocate JackData in jack_initDriver().  After
that, we can safely remove all audioOutput->data==NULL checks (and
replace them with assertions).
2008-08-26 08:27:15 +02:00
Max Kellermann
83215bf9ce jack: added freeJackClient()
No need to destroy the JackData object when an error occurs, since
jack_finishDriver() already frees it.  Only deinitialize the jack
library, introduce freeJackClient() for that, and move code from
freeJackData().
2008-08-26 08:27:15 +02:00
Max Kellermann
dc989987ab jack: initialize jd->client after !jd check
Prepare the next patch: make the "!jd" check independent of the
jd->client initialization.  This way we can change the "jd"
initialization semantics later.
2008-08-26 08:27:15 +02:00
Max Kellermann
2383231123 jack: eliminate superfluous freeJackData() calls
connect_jack() invokes freeJackData() in every error handler, although
its caller also invokes this function after a failure.  We can save a
lot of lines in connect_jack() by removing these redundant
freeJackData() invocations.
2008-08-26 08:27:15 +02:00
Max Kellermann
f46de2c32f mp3, flac: check for seek command after decoder_read()
When we introduced decoder_read(), we added code which aborts the read
operation when a decoder command arrives.  Several plugins however did
not expect that when they were converted to decoder_read().  Add
proper checks to the mp3 and flac decoder plugins.
2008-08-26 08:27:15 +02:00
Max Kellermann
e530181e23 check decoder_command!=NONE instead of decoder_command==STOP
The code said "decoder_command==STOP" because that was a conversion
from the old "dc->stop" test.  As we can now check for all commands in
one test, we can simply rewrite that to decoder_command!=NONE.
2008-08-26 08:27:15 +02:00
Max Kellermann
4515ac5ecb mp3: converted the MUTEFRAME_ macros to an enum
Also introduce MUTEFRAME_NONE; previously, the code used "0".
2008-08-26 08:27:14 +02:00
Max Kellermann
95fff55d7e mp3: converted the DECODE_ constants to an enum 2008-08-26 08:27:14 +02:00
Max Kellermann
1c196478b6 added flag "decoder.seeking"
This flag is used internally; it is set by decoder_seek_where(), and
indicates that the decoder plugin has begun the seek process.  It is
used for the case that the decoder plugin has to read data during the
seek process.  Before this patch, that was impossible, because
decoder_read() would refuse to read data unless dc->command is NONE.
This patch is kind of a dirty workaround, and needs to be redesigned
later.
2008-08-26 08:27:14 +02:00
Max Kellermann
cf139dc012 wavpack: don't use "isp" before initialization
The old code called can_seek() with the uninitialized pointer
"isp.is".  Has this ever worked?  Anyway, initialize "isp" first, then
call can_seek(&isp).
2008-08-26 08:27:14 +02:00
Max Kellermann
2e822a577d wavpack: moved code to wavpack_open_wvc()
Move everything related to finding and initializing the WVC stream to
wavpack_open_wvc().  This greatly simplifies its error handling and
the function wavpack_streamdecode().
2008-08-26 08:27:14 +02:00
Max Kellermann
af58de6543 simplified code in the ogg decoder plugin
Return early when the player thread sent us a command.  This saves one
level of indentation.
2008-08-26 08:27:14 +02:00
Max Kellermann
940ecf5345 added decoder_read()
On our way to stabilize the decoder API, we will one day remove the
input stream functions.  The most basic function, read() will be
provided by decoder_api.h with this patch.  It already contains a loop
(still with manual polling), error/eof handling and decoder command
checks.  This kind of code used to be duplicated in all decoder
plugins.
2008-08-26 08:27:14 +02:00
Max Kellermann
d80260ab4e wavpack: added InputStreamPlus.decoder
The "decoder" object reference will be used by another patch.
2008-08-26 08:27:14 +02:00
Max Kellermann
a1b430cb88 oggvorbis: don't detect OGG header if stream is not seekable
If the input stream is not seekable, the try_decode() function
consumes valuable data, which is not available to the decode()
function anymore.  This means that the decode() function does not
parse the header correctly.  Better skip the detection if we cannot
seek.  Or implement better buffering, something like unread() or
buffered rewind().
2008-08-26 08:27:13 +02:00
Max Kellermann
7bbca0842d added AacBuffer.decoder
We need the decoder object at several places in the AAC plugin.  Add
it to mp3DecodeData, so we don't have to pass it around in every
function.
2008-08-26 08:27:13 +02:00
Max Kellermann
468f61d587 mp3: added mp3DecodeData.decoder
We need the decoder object at several places in the mp3 plugin.  Add
it to mp3DecodeData, so we don't have to pass it around in every
function.
2008-08-26 08:27:13 +02:00
Max Kellermann
7653ab434e mp3: audio_linear_dither() returns mpd_sint16
The return value of audio_linear_dither() is always casted to
mpd_sint16.  Returning long does not make sense, and consumed 8 bytes
on a 64 bit platform.
2008-08-26 08:27:13 +02:00
Max Kellermann
9c823d67a7 mp3: changed outputBuffer's type to mpd_sint16[]
The output buffer always contains mpd_sint16; declaring it with that
type saves several casts.
2008-08-26 08:27:13 +02:00
Max Kellermann
2a9608536c mp3: moved num_samples calculation out of the loop
The previous patch removed all loop specific dependencies from the
num_samples formula; we can now calculate it before entering the loop.
2008-08-26 08:27:13 +02:00
Max Kellermann
3f55b5a1e4 mp3: eliminated outputPtr
The output buffer is always flushed after being appended to, which
allows us to assume it is always empty.  Always start writing at
outputBuffer, don't remember outputPtr.
2008-08-26 08:27:13 +02:00
Max Kellermann
f0bcb4a44a mp3: don't do a second flush in mp3_decode()
The previous patch made mp3Read() flush the output buffer in every
iteration, which means we can eliminate the flush check after invoking
mp3Read().
2008-08-26 08:27:13 +02:00
Max Kellermann
2e8bd3ae1d mp3: always flush directly after decoding/dithering
Since we try to fill the buffer in every iteration, we assume that we
should flush the output buffer at the end of each iteration.
2008-08-26 08:27:12 +02:00
Max Kellermann
af83ac5ec6 mp3: dither a whole block at a time
Fill the whole output buffer at a time by using dither_buffer()'s
ability to decode blocks.  Calculate how many samples fit into the
output buffer before each invocation.
2008-08-26 08:27:12 +02:00
Max Kellermann
e99536e8eb mp3: moved dropSamplesAtEnd check out of the loop
Simplifying loops for performance: why check dropSamplesAtEnd in every
iteration, when we could modify the loop boundary?  The (writable)
variable samplesLeft can be eliminated; add a write-once variable
pcm_length instead, which is used for the loop condition.
2008-08-26 08:27:12 +02:00
Max Kellermann
e4c6c01903 mp3: make samplesPerFrame more local
The variable samplesPerFrame is used only in one single closure.  Make
it local to this closure.  The compiler will probably convert it to a
register anyway.
2008-08-26 08:27:12 +02:00
Max Kellermann
60a155624c mp3: unsigned integers 2008-08-26 08:27:12 +02:00
Max Kellermann
f667da1b46 mp3: removed double cmd==STOP check
cmd has already been checked before, it cannot have changed meanwhile
because it is a local variable.
2008-08-26 08:27:12 +02:00
Max Kellermann
09fbbdc366 mp3: moved code to dither_buffer()
Preparing for simplifying and thus speeding up the dithering code:
moved dithering to a separate function which contains a trivial loop.
With this patch, only one sample is dithered at a time, but the
following patches will allow us to dither a whole block at a time,
without complicated buffer length checks.
2008-08-26 08:27:12 +02:00
Max Kellermann
d9583aa95b mp3: don't check dropSamplesAtStart in the loop
Performance improvement by moving stuff out of a loop: skip part of
the first frame before entering the loop.
2008-08-26 08:27:12 +02:00
Max Kellermann
df251a9960 assert song->url != NULL 2008-08-26 08:27:11 +02:00
Max Kellermann
e99333167e aac: support decoding AAC streams
Copy some code from aac_decode() to aac_stream_decode() and apply
necessary changes to allow streaming audio data.  Both functions might
be merged later.
2008-08-26 08:27:11 +02:00
Max Kellermann
5300f79ca9 aac: splitted aac_parse_header() from initAacBuffer()
initAacBuffer() should really only initialize the buffer; currently,
it also reads data from the input stream and parses the header.  All
of the AAC buffer code should probably be moved to a separate library
anyway.
2008-08-26 08:27:11 +02:00
Max Kellermann
351dda01bd aac: check buffer lengths
The AAC plugin sometimes does not check the length of available data
when checking for magic prefixes.  Add length checks.
2008-08-26 08:27:11 +02:00
Max Kellermann
9131f9ebfe aac: use fillAacBuffer() instead of manual reading
Eliminate some duplicated code by using fillAacBuffer().
2008-08-26 08:27:11 +02:00
Max Kellermann
00c47b3c85 find AAC frames
Find AAC frames in the input and skip invalid data.  This prepares AAC
streaming.
2008-08-26 08:27:11 +02:00
Max Kellermann
f43e39047d aac: moved code to adts_check_frame()
adts_check_frame() checks whether the buffer head is an AAC frame, and
returns the frame length.
2008-08-26 08:27:11 +02:00
Max Kellermann
b7ad3e4121 aac: moved code to aac_buffer_shift()
Shifting from the buffer queue is a common operation, and should be
provided as a separate function.  Move code to aac_buffer_shift() and
add a bunch of assertions.
2008-08-26 08:27:11 +02:00
Max Kellermann
a3cc928c71 aac: use inputStreamAtEOF()
When checking for EOF, we should not check whether the read request
has been fully satisified.  The InputStream API does not guarantee
that readFromInputStream() always fills the whole buffer, if EOF is
not reached.  Since there is the function inputStreamAtEOF() dedicated
for this purpose, we should use it for EOF checking after
readFromInputStream()==0.
2008-08-26 08:27:10 +02:00
Max Kellermann
35858dfe3a aac: don't depend on consumed data in fillAacBuffer()
Fill the AacBuffer even when nothing has been consumed yet.  The
function should not check for consumed data, but for free space at the
end of the buffer.
2008-08-26 08:27:10 +02:00
Max Kellermann
2a14141121 aac: simplified fillAacBuffer()
Return instead of putting all the code into a if-closure.  That saves
one level of indentation.
2008-08-26 08:27:10 +02:00
Max Kellermann
1d18f0089a aac: make adtsParse() void
adtsParse() always returns 1, and its caller does not use the return
value.
2008-08-26 08:27:10 +02:00
Max Kellermann
0ca8f9ac49 aac: use size_t 2008-08-26 08:27:10 +02:00
Max Kellermann
a6332fd13b aac: removed unused initAacBuffer() parameters
Since we eliminated the parameters retFileread and retTagsize in all
callers, we can now safely remove it from the function prototype.
2008-08-26 08:27:10 +02:00
Max Kellermann
4ca24b960b eliminate unused variables in the AAC decoder 2008-08-26 08:27:10 +02:00
Max Kellermann
82ca4cf8ce added InputStream.ready
The flag "ready" indicates whether the input stream is ready and it
has parsed all meta data.  Previously, it was impossible for
decodeStart() to see the content type of HTTP input streams, because
at that time, the HTTP response wasn't parsed yet.
2008-08-26 08:27:10 +02:00
Max Kellermann
6120635f06 added decoder_plugin_register()
With the functions decoder_plugin_register() and
decoder_plugin_unregister(), decoder plugins can register a
"secondary" plugin, like the flac input plugin does this for
"oggflac".
2008-08-26 08:27:09 +02:00
Max Kellermann
a68ef497f5 don't call quitDecode() in waitOnDecode()
To make the code more consistent, call quitDecode() only at the end of
decodeParent().
2008-08-26 08:27:09 +02:00
Max Kellermann
e8bd9ddc9f moved code to player_thread.c
Move code which runs in the player thread to player_thread.c.  Having
a lot of player thread code in decode.c isn't easy to understand.
2008-08-26 08:27:09 +02:00
Max Kellermann
6104e9690e moved code to crossfade.c
decode.c should be a lot smaller; start by moving all code which
handles cross-fading to crossfade.c.  Also includes camelCase
conversion.
2008-08-26 08:27:09 +02:00
Max Kellermann
2650b9eb31 added inline function audio_format_time_to_size()
Make the code more readable by hiding big formulas in an inline
function with a nice name.
2008-08-26 08:27:09 +02:00
Max Kellermann
0aedf7dd5a pass max_chunks to calculateCrossFadeChunks()
Make calculateCrossFadeChunks() more generic and portable by
eliminating global variable access.
2008-08-26 08:27:09 +02:00
Max Kellermann
0fc2422cd0 converted MpdTagItem.type to an enum
Don't use CPP macros when you can use C enum... this also allows
better type checking.
2008-08-26 08:27:09 +02:00
Max Kellermann
e754ed01a7 renamed functions in decoder_list.h
InputPlugin to decoder_plugin, and no camelCase.
2008-08-26 08:27:09 +02:00
Max Kellermann
772d3da98a no camel case in struct decoder_plugin 2008-08-26 08:27:08 +02:00
Max Kellermann
f1a014d094 renamed the InputPlugin function types
Continuing the effort to rename InputPlugin to decoder_plugin...
2008-08-26 08:27:08 +02:00
Max Kellermann
41c5fbbb07 renamed inputPlugin.* to decoder_list.*
Since inputPlugin.c manages the list of registered decoders, we should
rename the source file.
2008-08-26 08:27:08 +02:00
Max Kellermann
f5711e28da moved decoder externs to inputPlugin.c
The decoder_plugin instances are only used inputPlugin.c, so move them
from the header file.
2008-08-26 08:27:08 +02:00
Max Kellermann
e41be362a1 renamed InputPlugin to struct decoder_plugin
"decoder plugin" is a better name than "input plugin", since the
plugin does not actually do the input - InputStream does.  Also don't
use typedef, so we can forward-declare it if required.
2008-08-26 08:27:08 +02:00
Max Kellermann
cdaa26c81d no busy-waiting for the player process
The function player_command() inherited the busy-waiting algorithm
from the old code; throw in a wait_main_task() to do idle waiting.
2008-08-26 08:27:08 +02:00
Max Kellermann
b1de50f994 converted PlayerControl.state to enum
Don't write CPP when you can express the same in C...  macros vs enum
is a good example for that.
2008-08-26 08:27:08 +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
c7384b65ac eliminate OUTPUT_BUFFER_DC_STOP, OUTPUT_BUFFER_DC_SEEK
(Ab)use the decoder_command enumeration, which has nearly the same
values and the same meaning.
2008-08-26 08:27:07 +02:00
Max Kellermann
67bf4b448d added decoder_get_url()
The wavpack decoder plugin implements a hack, and it needs the song
URL for that.  This API (and the hack) should be revised later, but
add that function for now.
2008-08-26 08:27:07 +02:00
Max Kellermann
c60209ff04 don't set dc->seekable in wavpack plugin
dc->seekable is already set by decodeStart().
2008-08-26 08:27:07 +02:00
Max Kellermann
dc4d774481 use a local "initialized" flag instead of dc->state
Since we want to hide mpd internals from the decoder plugins, the
plugins should not check dc->state whether they have already called
decoder_initialized().  Use a local variable to track that.
2008-08-26 08:27:07 +02:00
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
2e9169de9d moved convState to struct decoder
Since we moved all PCM conversions to decoder_data(), the attribute
convState isn't being used anymore by the OutputBuffer code.  Move it
to struct decoder.
2008-08-26 08:27:06 +02:00
Max Kellermann
1b845f94a0 moved struct AudioFormat to audio_format.h
We want to expose the AudioFormat structure to plugins; remove some
clutter by moving its declaration to a separate header file.
2008-08-26 08:27:06 +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
ea51f73285 tail_chunk() returns ob_chunk pointer
Code simplification: since we are not using in-band signalling with
the chunk index anymore, we can just return a pointer to the tail
chunk instead of the index.
2008-08-26 08:27:05 +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
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
8814c0c898 use the notify library in main_notify.c
Avoid some duplicated code in main_notify.c.
2008-08-26 08:27:05 +02:00
Max Kellermann
4f80f53c29 do not sleep after openAudioDevice()
After the decoder has been initialized and the audio device has been
opened, don't sleep.  The decoder plugin won't do anything special nor
will it care to wake us up for some reason.
2008-08-26 08:27:04 +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
241cd043ca invoke the notify API directly
Don't use wrappers like player_wakeup_decoder_nb().  These have been
wrappers calling notify.c functions, for compatibility with the
existing code when we migrated to notify.c.
2008-08-26 08:27:04 +02:00
Max Kellermann
87beded44f removed "else"
The "if" block breaked out of the loop.  That means we can move the
code out of the "else" block.
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
726c6e86d3 don't busy wait for the decoder thread
Busy wait loops are a bad thing, especially when the response time can
be very long - busy waits eat a lot of CPU, and thus slow down the
other thread.  Since the other thread will notify us when it's ready,
we can use notify_wait() instead.
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
180d78a8e6 don't set pc->errored_song in decodeStart()
pc->errored_song is already set by decodeParent() in the player thread
when we set dc->error; no need to set it in the decoder thread.
2008-08-26 08:27:03 +02:00
Max Kellermann
d507ff28c8 added dc.next_song, renamed pc.current_song
Since pc->current_song denotes the song which the decoder should use
next, we should move it to DecoderControl.  This removes one internal
PlayerControl struct access from the decoder code.

Also add pc.next_song, which is manipulated by the playlist code, and
gets copied to dc.next_song as soon as the decoder is started.
2008-08-26 08:27:03 +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
c003778454 fix warnings in the HTTP client
Fix a "unused argument" warning, and several warnings regarding void
pointer calculation.
2008-08-25 15:49:06 +02:00
Max Kellermann
35918c9901 fixed ringbuf.c warnings
Fix a "signed/unsigned comparison warning", and several void pointer
math warnings.
2008-08-25 15:49:06 +02:00
Eric Wong
a889684acd http: hopefully allow seeking to work on static files
git-svn-id: https://svn.musicpd.org/mpd/trunk@7398 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-30 02:43:36 +00: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
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
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
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
Max Kellermann
7dc1f3117c wake up player on demand
The decoder should not wake up the player when it did not produce a
flushed chunk.  Move the decoder_wakeup_player() call to
flushOutputBuffer() and invoke it only if the buffer was previously
empty.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7336 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:21:00 +00:00
Max Kellermann
91b43b481d unlink the socket before bind()
If a unix domain socket already exists, bind() fails.  Unlink the
socket file.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7335 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:56 +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
1db6478491 fix several errors/warnings which only appear with -O3
git-svn-id: https://svn.musicpd.org/mpd/trunk@7333 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:20:45 +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
14529af732 pass dc to decoder_task()
git-svn-id: https://svn.musicpd.org/mpd/trunk@7323 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:50 +00:00
Max Kellermann
66f1d1ddb3 pass pc to set_current_song()
git-svn-id: https://svn.musicpd.org/mpd/trunk@7322 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:44 +00:00
Max Kellermann
1465bfab82 pass pc to player_task()
Another global variable cleanup patch.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7321 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:38 +00:00
Max Kellermann
8098d8ff8e whitespace cleanup
git-svn-id: https://svn.musicpd.org/mpd/trunk@7320 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:32 +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
159fb3803b removed "volatile" from OutputBufferChunk properties
There is no danger that gcc will optimize access to OutputBufferChunk
properties, since decoder and player work in different chunk objects.
It is safe to remove "volatile" here.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7318 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:54 +00:00
Max Kellermann
b0e47fce09 pass pc to player notify functions
Same as the previous patch: less global variables.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7317 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:49 +00:00
Max Kellermann
7642d10fe9 pass DecoderControl object to decoder_sleep()
Less global variables: at any invocation of decoder_sleep(), we have a
reference to the DecoderControl anyway, so we should pass it.  This
costs less than having to call getPlayerData() in every tiny
function.  Maybe some day we will be able to have multiple decoders at
the same time...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7316 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:43 +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
b688134586 remove the local variable "end"
"end" is not being used anymore, since we moved most OutputBuffer
struct accesses into methods.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7314 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:32 +00:00
Max Kellermann
0c46dd6831 don't use short chunk numbers
Don't be mean with integer sizes.  Although we will probably never
have more than 32k buffered chunks, we should use 32 bit integers for
addressing them.  We do not save very much (some of the saved space is
eaten by alignment anyway), but we save at least one assembler
instruction for converting short to int.

This change requires some more explicit casts, because gcc was less
picky when comparing short with a full int.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7313 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:28 +00:00
Max Kellermann
20c4638a2e added output_buffer_skip()
First patch without camelCase ;)

output_buffer_skip() lets us eliminate advanceOutputBufferTo(), and
removes yet another external OutputBuffer struct access.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7312 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:18:19 +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
eb5d51c988 fixed another shadow warning
git-svn-id: https://svn.musicpd.org/mpd/trunk@7307 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:17:22 +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
4b2a10825d fix typo in comment
git-svn-id: https://svn.musicpd.org/mpd/trunk@7305 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:17:01 +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
f0e28ede4d fix deadlock at end of song
Now that we do proper locking and signalling instead of continuous
polling for IPC, a deadlock was found: at the end of a song, the
player thread waits until the main thread sets pc->queueState from
PLAYER_QUEUE_DECODE to PLAYER_QUEUE_PLAY.  He is never woken up, since
syncPlaylistWithQueue() does not activate the notification.  I added
wakeup_player_nb() to setQueueState(), since the player must be
signalled whenever pc->queueState changes.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7303 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:50 +00:00
Eric Wong
9cfb4c0390 decode: fix some uninitialized variable warnings
They're probably not needed, but less noise => faster debugging

git-svn-id: https://svn.musicpd.org/mpd/trunk@7302 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:44 +00:00
Eric Wong
e566c4c64c decode: fix unsigned comparision and add some paranoid assertions
git-svn-id: https://svn.musicpd.org/mpd/trunk@7301 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:37 +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
dd20681daa missing const in disabled code path
git-svn-id: https://svn.musicpd.org/mpd/trunk@7298 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:18 +00:00
Max Kellermann
ee64bba4d9 some assertions to check the unsigned changes
git-svn-id: https://svn.musicpd.org/mpd/trunk@7297 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:13 +00:00
Max Kellermann
1ad2f07a39 use size_t in audio.c
Buffer sizes should be size_t.  This is safe here, at least not
unsafer than without the patch.  I have no idea why audioBufferSize
and audioBufferPos were explicitly declared as signed integer.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7296 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:08 +00:00
Max Kellermann
c9d80d6090 use free()/malloc() instead of realloc()
When growing the audioOutput->convBuffer, we can use free()+malloc()
instead of realloc(), which saves a memcpy().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7295 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:03 +00:00
Max Kellermann
1d18ca6909 use size_t in audioOutput.c internals
git-svn-id: https://svn.musicpd.org/mpd/trunk@7294 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:58 +00:00
Max Kellermann
01bf822896 use size_t and constant pointer in ao plugins
The audio output plugins should get a constant pointer, because they
must not modify the buffer.  Since the size is a non-negative buffer
size in bytes, we should change its type to size_t.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7293 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:52 +00:00
Max Kellermann
a2380928db use size_t for pcm_sizeOfConvBuffer() result
In my previous patch set, I forgot to change the
pcm_sizeOfConvBuffer() invocation in convertAudioFormat() to also use
size_t.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7292 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:40 +00:00
Max Kellermann
2bd2957a7a yet more unsigned integers
calculateCrossFadeChunks() still returns int, although the caller uses
it as an unsigned value.  Since the function body checks for negative
values, it is safe to cast to unsigned.

crossFade() takes signed parameters, although it callers pass unsigned
integers.  Change declaration to unsigned.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7291 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:35 +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
Max Kellermann
4e0891337a whitespace cleanup
git-svn-id: https://svn.musicpd.org/mpd/trunk@7286 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:00 +00:00
Max Kellermann
7503518bac added inline function successor()
The new function successor() can be used to simplify a lot of code
lines and saves a lot of "i+>=buffered_chunks" checks.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7285 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:55 +00:00
Max Kellermann
079f13bc7d moved currentChunk into OutputBuffer
currentChunk is a global variable, which renders the whole output
buffer code non-reentrant.  Although this is not a real problem since
there is only one global output buffer currently, we should move it to
the OutputBuffer struct.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7284 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:50 +00:00
Max Kellermann
4ee8396f41 use the notify API in the main thread
git-svn-id: https://svn.musicpd.org/mpd/trunk@7283 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:45 +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
0146fbe3ce use the pthread API in notify.c
This patch rewrites notify.c to use the pthread API, namely
pthread_mutex and pthread_cond.  This is a lot cheaper and easier than
the pipe() hack.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7280 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:25 +00:00
Max Kellermann
38e0dafc4c rename the notify.c methods
Use "notify" as a prefix rather than suffix.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7279 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:19 +00:00
Max Kellermann
00a16b49ba use break instead of quitDecode()+return
The code paths which return from the functions all have to call
quitDecode().  If we simply break instead of calling quitDecode()
explicitly, this function gets called in the last line of this
function anyway.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7278 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:14 +00:00
Max Kellermann
646260b19e moved expression to audioFormatSizeToTime()
The multi-line expression which calculates sizeToTime is hard to read,
partly because "cb->audioFormat." is too long.  Create a separate
inline function in audio.h for that.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7277 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:09 +00:00
Max Kellermann
dc55e13ca1 let calculateCrossFadeChunks() decide
Moved the decision whether to cross-fade the current song to
calculateCrossFadeChunks().  This simplifies the function
decoderParent() and eliminates one layer of indentation.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7276 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:01 +00:00
Max Kellermann
b009b2a437 moved code to playChunk()
Similar to the crossFade() patch: pass chunk objects to playChunk(),
simplify decodeParent() by removing clutter.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7275 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:56 +00:00
Max Kellermann
2e648b57f3 added outputBufferShift()
Hiding OutputBuffer internals, yet again.  Two more assertions.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7274 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:51 +00:00
Max Kellermann
11a5728e1d continue main loop instead of nesting loops
To unify the decoderParent() main loop some more, use it to wait for
the decoder to change the song.  Only one single processDecodeInput()
caller left after this patch.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7273 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:45 +00:00
Max Kellermann
f25ff42639 sleep when waiting for cross-fade chunks
When there are not enough decode cross-fade chunks in the buffer yet,
the current code does busy-wait, which will delay the decoder even
more.  sleep instead, expecting the decoder to wake us up.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7272 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:41 +00:00
Max Kellermann
9760325ee6 moved code to crossFade()
Calling crossFade() with the chunk objects is easier than unrolling
all the chunk properties manually, and decodeParent() can really use
more of these simplifications.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7271 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:36 +00:00
Max Kellermann
bc20b64302 use sizeof(chunk.data) instead of CHUNK_SIZE
sizeof() is the more "natural" or "direct" access to the buffer size,
instead of a macro happening to be used to the buffer declaration.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7270 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:30 +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
Max Kellermann
68a625b5b8 moved CHUNK_SIZE to outputBuffer.h
The chunk size should be in outputBuffer.h since the output buffer
code is its primary user.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7268 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:17 +00:00
Max Kellermann
7a6c31ae06 added outputBufferChunkData()
Hiding OutputBuffer internals, again.  We get an extra assertion in
return.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7267 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:11 +00:00
Max Kellermann
71b24e0950 removed "quit"
The variable "quit" can be removed, since its only setter can use
"break" instead, just like the other code paths.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7266 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:05 +00:00
Max Kellermann
e9b7aae3f0 do not reset nextChunk
The variables "nextChunk" and "crossFadeChunks" are only used when
doCrossFade==1.  This means that we do not have to reset these as long
as doCrossFade!=1.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7265 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:13:00 +00:00
Max Kellermann
4e60343e55 added outputBufferRelative()
The cross-fade check is still very complicated whenever it uses
OutputBuffer internals.  Greatly simplify another check by introducing
outputBufferRelative().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7264 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:53 +00:00
Max Kellermann
50dc380f23 added outputBufferEmpty()
Another "don't use OutputBuffer internals" patch.  This ignores the
copied "end" value, but I do not think that has ever been a real
issue.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7263 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:47 +00:00
Max Kellermann
e626028b41 moved check to outputBufferAbsolute()
decoderParent() uses a lot of OutputBuffer internals to see whether
cross-fading should be started.  Move these checks to outputBuffer.c,
which also simplifies decoderParent().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7262 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:42 +00:00
Max Kellermann
a546428263 make variables more local
Declare the variables "test" and "fadePosition" in the scope where
they are really used.  This removes some of the clutter in the
function decodeParent().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7261 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:36 +00:00
Max Kellermann
b89b019723 moved the initial buffering code into the big loop
Eliminating some duplicated and.  This also decreases the number of
lines calling processDecodeInput().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7260 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:31 +00:00
Max Kellermann
aaebd9ef2b some comments in decode.c
I have spent some time to understand decodeParent(), which does a lot
of obfuscated magic...  I find it useful to help others to also
understand it, so I wrote a few comments.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7259 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:26 +00:00
Max Kellermann
7ee436b435 integrated macro handleDecodeStart() into caller
Another patch indended to improve the CPP macro hell.  This enlarges
the function decodeParent(), but it cannot be converted into a
standalone function easily, because it references so many local
variables.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7258 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:21 +00:00
Max Kellermann
753b5cf360 use clearOutputBuffer()
clearOutputBuffer() also resets currentChunk; this might resolve a
theoretical bug.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7257 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:16 +00:00
Max Kellermann
199ea5f2c1 do not check dc->start after loop
dc->start cannot be true after the loop, because it was the loop
condition.  dc->start could have been set by another thread between
the while loop and the if, but I suspect this is not the case the
author intended, so we just remove the dc->start check.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7256 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:11 +00:00
Max Kellermann
e63f388b04 use DECODE_ERROR_NOERROR instead of 0
In my opinion, the code becomes more readable when we explicitly check
"==NOERROR" instead of an implicit 0 check.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7255 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:07 +00:00
Max Kellermann
f6ed3eaeae converted macro processDecodeInput() to function
Macros are ugly, and multi-line macros are even more ugly.  This patch
converts processDecodeInput() to a C function.  The disadvantage may
be that the function does not have access to the caller's local
variables, which might be regarded as an advantage on the other hand.
For this reason, we have to pass variable references.  This costs a
tiny bit of performance, but it's worth eliminating this monster
macro, and further patches will optimize this cost down.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7254 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:12:01 +00:00
Max Kellermann
82fbf1a24c added clearPlayerQueueLocked()
since clearPlayerQueue() is always called within
lockPlaylistInteraction() / unlockPlaylistInteraction(), it simplifies
the code to add another function which calls these three functions.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7253 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:11:56 +00:00
Max Kellermann
7aa78d9b4a don't set quit=1 before break
Instead of setting quit=1, we can simply break out of the loop.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7252 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:11:51 +00:00
Max Kellermann
fae23a5111 simplified some code in decode.c
The block after "if" breaks out of the loop.  To make the code a
little bit more readable, don't write the rest in an "else" block,
since this code path does not break.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7251 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:11:46 +00:00
Max Kellermann
a7b19012d3 add method availableOutputBuffer()
The method availableOutputBuffer() calculates how many chunks are in
use.  This simplifies code which needs this information, and it can
run without knowing OutputBuffer internals.  The function knows how to
calculate this when begin>end; this might have been a bug in
decodeParent(), which does not.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7250 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:11:41 +00:00
Max Kellermann
0defe87da7 replace advanceOutputBufferTo() with trivial assignment
After the previous patch, it is clear that the loop in
advanceOutputBufferTo() can be replaced with a simple assignment.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7249 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:11:34 +00:00
Max Kellermann
4150a49b36 removed unused parameters from advanceOutputBufferTo()
The parameter "currentChunkSent" is not used and can be dropped.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7248 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:11:29 +00:00
Max Kellermann
1ecebd4686 moved code to function tailChunk()
This patch removes some clutter from decodeParent() by moving some
code out.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7247 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:11:23 +00:00
Max Kellermann
63b55b9a48 use free()+malloc() instead of realloc()
realloc() has to copy data to the new buffer.  Since convBuffer
contains temporary data only, we can safely use free() plus a new
malloc(), which saves the mempy().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7246 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:11:17 +00:00
Max Kellermann
d3f72d1023 some documentation about OutputBuffer
git-svn-id: https://svn.musicpd.org/mpd/trunk@7245 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:08:35 +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
b323040489 outputBuffer: remove unused variable
[merged r7185 from branches/ew]

git-svn-id: https://svn.musicpd.org/mpd/trunk@7243 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:08:22 +00:00
Eric Wong
3c52652032 song: document get_song_url()
[merged r7184 from branches/ew]

git-svn-id: https://svn.musicpd.org/mpd/trunk@7242 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:08:18 +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
d742fa6596 whitespace cleanup
Clean up some space indentations, replace with tabs.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7239 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:07:44 +00:00
Max Kellermann
6142959456 proper bind error message for unix socket
git-svn-id: https://svn.musicpd.org/mpd/trunk@7238 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:07:37 +00:00
Max Kellermann
86d6ba077b provide switches for TCP and unix sockets
autoconf flags for enabling and disabling TCP and unix domain socket
support.  Embedded machines without a TCP stack may be better off
without TCP support.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7236 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:07:24 +00:00
Max Kellermann
d4f319deaf support listening on unix domain sockets
This trivial patch addresses bug 1639.  When a bind_to_address
argument starts with a slash, assume that it is the address of a Unix
domain socket.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7235 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:07:18 +00:00
Max Kellermann
623a86f389 use constant pointers when possible
It is a good practice to constify pointers when their dereferenced
data is not modified within the functions or its descendants.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7234 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:07:11 +00:00
Max Kellermann
83e937320b eliminate unused parameters
The parameter "port" is not actually used by establishListen(), and
can be removed.  This also allows establishListen() to be used for
socket addresses which have no port.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7233 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:07:06 +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
c069b89d86 use unsigned integers in outputBuffer.c
The chunk index cannot be negative.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7231 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:06:57 +00:00
Max Kellermann
b60789dd8c fix sign compare warnings
Do explicit casts before comparing signed with unsigned.  The one in
log.c actually fixes another warning: in the expanded macro, there may
be a check "logLevel>=0", which is always true.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7230 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:06:52 +00:00
Max Kellermann
c011ab8105 deconstify input buffer for iconv()
Unfortunately, the function iconv() wants a non-const input buffer.
In this context, we only have a const pointer, which emits a correct
gcc warning.  Work around this ugliness with an union-deconst hack.
This is optimized away in the binary.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7229 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:06:45 +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
Max Kellermann
665eab26f3 use unsigned integers in decoder.c
Use unsigned integers in decoderParent() for chunk numbers which
cannot be negative.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7226 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:06:17 +00:00
Eric Wong
7261a12b4c include os_compat.h in tarball distributions
Thanks to Jérome Perrin

git-svn-id: https://svn.musicpd.org/mpd/trunk@7224 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-30 23:43:09 +00:00
Eric Wong
6e13b75186 notify: initialize variable to keep valgrind from bitching
We don't really care what that variable is, so it might as
well be uninitialized, but valgrind does...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7220 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-27 05:32:27 +00:00
Eric Wong
53be85e1b1 notify: more cleanups, add error checking for pipe errors
Don't bother initializing the junk buffer, we really don't care.
The array was also unnecessary and ugly.

Also, avoid returning the byte count we read/wrote since it
unnecessarily exposes internal details of the implementation to
the callers.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7219 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:39:13 +00:00
Eric Wong
19d4f6df18 interface: use a saner fdmax for select(2) when closing errored interfaces
git-svn-id: https://svn.musicpd.org/mpd/trunk@7218 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:39:07 +00:00
Eric Wong
232c9f6c41 notify: cleanups
* move set_nonblock{,ing}() into utils.c since we use it
elsewhere, too
* add proper error checking to set_nonblocking()
* use os_compat.h instead of individually #includ-ing system headers

git-svn-id: https://svn.musicpd.org/mpd/trunk@7217 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:39:03 +00:00
Max Kellermann
70dbc2b0e7 send notify signal after SIGCONT
When the decoder receives SIGCONT during waitNotify(), the kernel
restarts the read() system call.  This lets the decoder process block
indefinitely, while the player process waits for it to react.  This
should probably be solved with a proper signal handler which aborts
the read() system call, but for now, we just write to the pipe to make
it wake up.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7216 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:58 +00:00
Max Kellermann
bf05ce161f notify the decoder instead of polling 100hz
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
2008-03-26 10:38:54 +00:00
Max Kellermann
1d97bbbdd9 unsigned counters
Use unsigned variables for storing the count of items or for iteration
variables.  Since there can never be a negative number of items, it
makes sense to use an unsigned data type here.  This change is safe
because the unsigned values are only used for adddressing array items.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7214 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:48 +00:00
Max Kellermann
e4779fa752 don't repeat select()
The interfaces main loop repeats the select() (non-blocking) after an
event was handled.  I do not see any reason for that, since all events
should be handled after the first select().  This double select() does
nothing than consume more CPU cycles.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7213 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:44 +00:00
Max Kellermann
f9e317ccbd unlimited select() timeout
mpd sets a 1s select() timeout for no reason.  This makes mpd wake up
the CPU, consume some cycles just to see there is nothing to do.  We
can save that by specifying NULL instead of a timeout.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7212 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:40 +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
99468b85ed networking: more assertions and cleanups to size_t/unsigned changes
Basically, I don't trust myself nor Max to not have bugs in our
code when switching over to unsigned types, so I've added more
assertions which will hopefully trip and force us to fix these
bugs before somebody can exploit them :)

Some cleanups for parameter parsing using strtol
and error reporting to the user.  Also, fix some completely
garbled indentation in inputStream_http.c

git-svn-id: https://svn.musicpd.org/mpd/trunk@7209 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:26 +00:00
Eric Wong
9ba7264362 audio.c: unsigned int functions return unsigned ints, not size_t
git-svn-id: https://svn.musicpd.org/mpd/trunk@7208 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:21 +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
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
Max Kellermann
27f12c173d use size_t
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
2008-03-26 10:38:07 +00:00
Max Kellermann
0692f6cd0a player: more assertions
Just one more assertion.  There should be more of that!

git-svn-id: https://svn.musicpd.org/mpd/trunk@7204 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:58 +00:00
Max Kellermann
c0787cc984 audio: use a machine word for array sizes
we do not save anything by limiting a variable to an unsigned char,
since the compiler aligns it at machine word size anyway.  however by
using the full machine word, we save one instruction, and we remove
the useless artificial limitation to 255.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7203 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:54 +00:00
Max Kellermann
5a62c5cf9c inputPlugins/oggvorbis: removed unused variables
The local variable eof can actually be replaced with a simple "break".
With a negative ret, the value of chunkpos can be invalidated, I am
not sure if this might have been a bug.

[ew: no, a negative ret will correspond to ret == OV_HOLE and ret
will be reset to zero leaving chunkpos untouched (code cleaned up
to make this more obvious]

git-svn-id: https://svn.musicpd.org/mpd/trunk@7202 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:49 +00:00
Max Kellermann
c5e1bc39e9 fix segmentation fault in song info parser
The database parser does not check whether the song object has been
initialized yet, which may lead to a NULL pointer dereference.  Add
this check.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7201 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:44 +00:00
Max Kellermann
c9e6201df5 fix strtok() related segmentation fault
strtok() may return NULL if the input is an empty string.  The
playlist parser did not check for that.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7200 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:40 +00:00
Max Kellermann
c5b524e376 eliminated duplicate initialization
Local variables which are never read before the first assignment don't
need initialization.  Saves a few bytes of text.  Also don't reset
variables which are never read until function return.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7199 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:36 +00:00
Max Kellermann
54b544c2f4 parse/initialize with the correct data type
When we expect an integer as result, why would we use the double
precision floating point parser?  strtol() is a better match, although
we should probably check for overflows...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7198 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:27 +00:00
Max Kellermann
b546bcfec6 fix "unreachable code" warning
There is unreachable code at several positions, e.g. after an
#if/#end, or after an endless loop.  Remove that.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7197 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:23 +00:00
Max Kellermann
66fe580642 explicitly downcast
Tools like "sparse" check for missing downcasts, since implicit cast
may be dangerous.  Although that does not change the compiler result,
it may make the code more readable (IMHO), because you always see when
there may be data cut off.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7196 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:17 +00:00
Max Kellermann
13c17c3d94 check the result of fopen() in all code paths
The while() loop only checks for interrupted system calls (which woudl
never happen if the signal mask were set up properly), but nobody
checks if the fopen() actually succeeds.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7195 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:10 +00:00
Max Kellermann
33e88ff8f9 zero is a valid file descriptor
Although it may not happen in mpd code, it is perfectly possible for a
newly allocated file descriptor to be zero.  For theoretical
correctness, allow 0.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7194 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:06 +00:00
Max Kellermann
c6ceceae8a moved handlePendingSignals() check into while() condition
For code unification: for me, it looks ugly to do a break in the
command in a while() block.  This belongs into the while condition.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7193 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:02 +00:00
Eric Wong
7c69161913 inputPlugins: add .oga suffix support for Ogg containers
From <http://wiki.xiph.org/index.php/MIME_Types_and_File_Extensions>:
> .oga - audio/ogg
>
>    * Ogg Audio Profile (audio in Ogg container)
>    * Applications supporting .oga, .ogv SHOULD support decoding
>      from muxed Ogg streams
>    * Covers Ogg FLAC, Ghost, and OggPCM
>    * Although they share the same MIME type, Vorbis and Speex
>      use different file extensions.
>    * SHOULD contain a Skeleton logical bitstream.
>    * Vorbis and Speex may use .oga, but it is not the
>      prefered(sic) method of distributing these files because of
>      backwards-compatibility issues.

Thanks to Qball and Rasi for the patch.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7191 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-20 05:27:04 +00:00
Eric Wong
5915fe55c0 listen.c: fix shadow warning here
git-svn-id: https://svn.musicpd.org/mpd/trunk@7182 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-02-05 10:20:46 +00:00
Eric Wong
77e3283973 compress.c: fix skips/distortion introduced in r7146
We need to ensure we're working with signed types when assigning
them.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7181 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-02-05 10:17:45 +00:00
Max Kellermann
6fbdc721d9 fix -Wconst warnings
[ew: cleaned up the dirty union hack a bit]
Signed-off-by: Eric Wong <normalperson@yhbt.net>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7180 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-02-05 10:17:33 +00:00
Eric Wong
22efbd5eca storedPlaylist: faster, but less accurate check for maximum sizes
There are still other ways to run the mpd server out of disk-space,
so permissions are still recommended to protect against malicious
users.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7179 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-29 09:26:39 +00:00
Eric Wong
b1cbe333a6 interface: abort if we expire while processing lines
If we keep processing expired interfaces in a loop,
we'll eventually close it and get fd < 0, causing
assertions to fail.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7168 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-27 23:10:45 +00:00
Eric Wong
2fcd63feb1 gcc.h: fix compilation with !(gcc >= 3)
git-svn-id: https://svn.musicpd.org/mpd/trunk@7167 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-27 23:10:41 +00:00
Eric Wong
688289b295 Revert the queue implementation and commands
It's too ugly and broken (both technically and usability-wise)
to be worth supporting in any stable release.

In one sentence: The queue is a very crippled version of the
playlist that takes precedence over the normal playlist.

How is it crippled?

* The "queueid" command only allows the queuing of songs
ALREADY IN THE PLAYLIST!  This promotes having the entire mpd
database of songs in the playlist, which is a stupid practice
to begin with.

* It doesn't allow for meaningful rearranging and movement
of songs within the queue.  To move a song, you'd need to
dequeue and requeue it (and other songs on the list).
Why?  The playlist already allows _all_ these features
and shows everything a client needs to know about the ordering
of songs in a _single_ command!

* Random was a stupid idea to begin with and unfortunately
we're stuck supporting it since we've always had it.  Users
should learn to use "shuffle" instead and not look at their
playlists.  Implementing queue because we have the problem of
random is just a bandage fix and digging ourselves a new hole.

This protocol addition was never in a stable release of mpd, so
reverting it will only break things for people following trunk;
which I'm not too worried about.  I am however worried about
long-term support of this misfeature, so I'm removing it.

Additionally, there are other points:

* It's trivially DoS-able:

(while true; do echo queueid $song_id; done) | nc $MPD_HOST $MPD_PORT

The above commands would cause the queue to become infinitely
expanding, taking up all available memory in the system.  The
mpd playlist was implemented as an array with a fixed (but
configurable) size limit for this reason.

* It's not backwards-compatible.  All clients would require
upgrades (and additional complexity) to even know what the
next song in the playlist is.  mpd is a shared architecture,
and we should not violate the principle of least astonishment
here.

This removes the following commands:
queueid, dequeue, queueinfo

Additionally, the status field of "playlistqueue: " is removed
from the status command.

While this DoS is trivial to fix, the design is simply too
broken to ever support in a real release.

The overloading of the "addid" command and the allowing of
negative numbers to be used as offsets is far more flexible.

This improved "addid" is completely backwards-compatible with
all clients, and does not require clients to have UI changes or
run additional commands to display the queue.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7155 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 20:21:07 +00:00
Eric Wong
29df70366c storedPlaylist: prevent potential DoS from stored playlist commands
While mpd has always protected against the infinite expansion of
the main playlist by limiting its size in memory, however the
new storedPlaylist code has never checked for this limit.

Malicious (or clumsy) users could repeatedly append songs to
stored playlists, causing files to grow increasingly large
on disk.  Attempting to load extremely large files into memory
will require mpd to slurp that all into memory, and ultimately
the file would be unusable by mpd because of the configurable
playlist size limit.

Now we limit stored playlists to the max_playlist_length
configuration variable set by the user (default is 16384).  We
will refuse to append to playlist files if they hit that limit;
and also refuse to load more than the specified amount of songs
into memory.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7154 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 20:20:59 +00:00
Eric Wong
3a1b3e3807 playlist: don't allow no-op/senseless movement of songs
This disables moving the bonkered moving of the current song to
a (negative) offset of itself (introduced in the last commit).

This also short circuits no-op moves when (from == to) and
avoid needless increasing of the playlist version and causes
clients to issue pointless no-op plchanges commands.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7153 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:47:04 +00:00
Eric Wong
e213ca4f8b playlist: allow move to specify offset from current song
If (and only if) there is a current song in the playlist,
(player could be stopped), allow the move destination
argument to be specified as a negative number.

This means moving any song (besides the current one) to the -1
position will allow it to be moved to the next song in the
playlist.  Moving any song to position -2 will move it
to the song after the next, and so forth.

Moving a song to -playlist.length will move it to the song
_before_ the current song on the playlist; so this will
work for repeating playlists, too.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7152 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:47:00 +00:00
Eric Wong
9eee1a81cf command: allow "addid" command to take an optional second argument, position
This will allow "addid \"song_url\" <pos>" to atomically insert a
song at any given playlist position.

If the add succeeds, but the actual movement fails (due to
invalid position), then the song_id will be deleted before
the command returns back to the client, and the client
will get an error response.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7151 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:56 +00:00
Eric Wong
2889b576eb command: cleanup integer argument validation for commands
git-svn-id: https://svn.musicpd.org/mpd/trunk@7150 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:53 +00:00
Eric Wong
2f0e5bfd85 addToPlaylist/addSongToPlaylist: printId argument changed to added_id
Instead of printing out the Id from playlist.c, instead set
the integer that added_id poitns to if added_id is non-NULL.

This makes the API cleaner and will allow us to use additional
commands to manipulate the newly-added song_id.  Callers
(handleAddId) that relied on printId to print it to the given
fd have now been modified to print the ID at a higher-level;
making playlist.c less-dependent on protocol details.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7149 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:49 +00:00
Eric Wong
2dafd9cd56 gcc.h: support mpd_fprintf__, with arguments shifted even further right
This will be used to check errors in command.c

git-svn-id: https://svn.musicpd.org/mpd/trunk@7148 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:44 +00:00
Eric Wong
262e515bee Cleanup checking for tests in src/ when building in separate dir
git-svn-id: https://svn.musicpd.org/mpd/trunk@7147 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:41 +00:00
Max Kellermann
c3ba1bb956 fixed "comparison between signed and unsigned"
Signed-off-by: Eric Wong <normalperson@yhbt.net>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7146 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:37 +00:00
Max Kellermann
0659d35951 fix -Waggregate-return
Signed-off-by: Eric Wong <normalperson@yhbt.net>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7145 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:30 +00:00
Max Kellermann
07eaad301a assume old flac api when FLAC_API_VERSION_CURRENT is not defined
the code is inconsistent when FLAC_API_VERSION_CURRENT is not defined:
sometimes version > 7 is assumed, and sometimes version <= 7.  solve
this by assuming the version is old when FLAC_API_VERSION_CURRENT is
not defined.
Signed-off-by: Eric Wong <normalperson@yhbt.net>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7144 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:26 +00:00
Max Kellermann
07adb14e3c fixed -Wshadow warnings
Signed-off-by: Eric Wong <normalperson@yhbt.net>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7143 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:21 +00:00
Max Kellermann
28008e6977 fixed invalid C prototypes
Signed-off-by: Eric Wong <normalperson@yhbt.net>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7142 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-26 12:46:09 +00:00
Eric Wong
7d66859277 ioops: make this zero-impact when compiling w/o zeroconf as well
This reduces the text size of the binary slightly when zeroconf
support is not built, and keeps the interface code cleaner as
well.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7133 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 10:03:34 +00:00
Eric Wong
a9b581f6c5 zeroconf: reformat (with mpd-indent.sh + manual tweaks)
Also, lower the impact of compiling this w/o zeroconf by
making the init/teardown functions static no-ops.

Eventually, we should separate the Bonjour and Avahi
code into separate files and have callbacks registered
for each one, avoiding the #ifdef mess we have now...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7132 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 10:03:28 +00:00
Eric Wong
776ccc89ad directory: allow db_file to reside on / once again
Oops!, I went back and documented the change going to parent_path(),
but forgot to change the code that was affected by it.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7131 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 07:32:59 +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
790e70cf25 directory.c: get rid of the horrid dirname(3) and libgen.h dependency
Ok, so basename(3) is even more brain-damaged, inconsistent
and/or broken than dirname(3) on most systems, but there are
broken implementations of it out there.  Just use our already
existing internal parent_path() function instead and get rid
of the only place where we look for libgen.h.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7129 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 07:22:22 +00:00
Eric Wong
b1cdf8dadf document parent_path()
git-svn-id: https://svn.musicpd.org/mpd/trunk@7128 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 07:22:18 +00:00
Eric Wong
b70912031d playerCloseAudio() is static
git-svn-id: https://svn.musicpd.org/mpd/trunk@7127 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 07:22:13 +00:00
Eric Wong
7de5f9cef1 player.c: introduce set_current_song to avoid needless repetition
git-svn-id: https://svn.musicpd.org/mpd/trunk@7126 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 07:22:08 +00:00
Eric Wong
00e0224996 song: updateSongInfo: left out charset conversion when going thread-safe
git-svn-id: https://svn.musicpd.org/mpd/trunk@7124 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:10:08 +00:00
Eric Wong
4c88ef34bb silence is constant, as is the buffer we pass to playAudio
git-svn-id: https://svn.musicpd.org/mpd/trunk@7123 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:10:02 +00:00
Eric Wong
2cc59816a6 Simplify decode cleanup logic a bit
DECODE_STATE_STOP is always set as dc->state, and dc->stop
is always cleared.  So handle it in decodeStart once rather
than doing it in every plugin.

While we're at it, fix a long-standing (but difficult to
trigger) bug in mpc_decode where we failed to return
if mpc_decoder_initialize() fails.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7122 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:09:56 +00:00
Eric Wong
5e7367c580 charConv: tie the buffer size for iconv() to our PATH_MAX constant
Although most PATH_MAX is higher than the 1k buffer we set, some
implementations will set a 256 (or even 64) byte PATH_MAX, so
we should be prepared for that.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7121 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:09:43 +00:00
Eric Wong
1b4de32706 storedPlaylist: remove the needless StoredPlaylist struct and just use List
Abstractions should reduce the amount of code and make things
easier to follow.  The StoredPlaylist struct did not do that, so
get rid of it and just use our standard linked list
implementation instead.

diffstat agrees with me that the abstraction is pointless:
3 files changed, 60 insertions(+), 90 deletions(-)

git-svn-id: https://svn.musicpd.org/mpd/trunk@7120 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:09:36 +00:00
Eric Wong
09936358fa storedPlaylist: cleanup API and avoid needless heap allocations + error checks
git-svn-id: https://svn.musicpd.org/mpd/trunk@7119 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:09:31 +00:00
Eric Wong
390ed29740 storedPlaylist: cleanup load function
* stop supporting unused parentlen block, I have no idea how it
was ever usable, but playlists don't work in subdirectories...

* myFgets is far easier to use than fgetc loops.

* Since we're using myFgets, we'll just skip lines that are too
long, rather than error out and bitch and moan about things...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7118 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:09:26 +00:00
Eric Wong
24c58132ec playlist: cleanup pathname generation for the "rm" command, too
git-svn-id: https://svn.musicpd.org/mpd/trunk@7117 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:09:23 +00:00
Eric Wong
68b9f41381 playlist: avoid the use of newStoredPlaylist for saving active playlists
It was a nice way to double the memory needed to write the
playlist to a file.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7116 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:09:18 +00:00
Eric Wong
47efe42321 Make utf8_to_fs_playlist_path universally accessible
git-svn-id: https://svn.musicpd.org/mpd/trunk@7115 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 10:07:34 +00:00
Eric Wong
49f8660f35 storedPlaylist: fix compile warning (last-second internal API change)
git-svn-id: https://svn.musicpd.org/mpd/trunk@7114 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 03:06:01 +00:00
Eric Wong
c3a47fe364 mpc_plugin: break out if a missed error branch
We shouldn't try to continue if mpc_decoder_initialize() fails.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7113 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 03:01:58 +00:00
Eric Wong
6fbbc642dd Revert r7111 and begin to properly fix storedPlaylist code
git-svn-id: https://svn.musicpd.org/mpd/trunk@7112 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-01 03:01:24 +00:00
Qball Cow
c75d33752a Don't let xstrdup(s) crash crash when s is NULL, but return Null in stead
git-svn-id: https://svn.musicpd.org/mpd/trunk@7111 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-31 18:41:08 +00:00
Eric Wong
a4ed0a8358 ogg_common: fix indent screwup
git-svn-id: https://svn.musicpd.org/mpd/trunk@7109 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-31 00:54:38 +00:00
Eric Wong
0d1a3539ad fix builds that only have FLAC >= 1.1.3 but not Ogg-Vorbis
git-svn-id: https://svn.musicpd.org/mpd/trunk@7108 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-31 00:54:32 +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
Qball Cow
0d26248a0d If clearing stored playlist fails, don't return error + OK. but only the error.
this was caused by always having the handleStoredPlaylist function return 0.


git-svn-id: https://svn.musicpd.org/mpd/trunk@7105 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-27 00:03:49 +00:00
Qball Cow
fd75619c3b Know about SND_PCM_STATE_RUNNING, might fix some bugs
git-svn-id: https://svn.musicpd.org/mpd/trunk@7077 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-16 15:46:54 +00:00
Qball Cow
704daecbf2 Fix possible wrong 'addition'
git-svn-id: https://svn.musicpd.org/mpd/trunk@7076 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-10 13:51:25 +00:00
Qball Cow
ba48dc18fd Fix replaygain for latest flac version.
The updated initialize method did not tell the libFLAC to look for the tag containing the replay information.


git-svn-id: https://svn.musicpd.org/mpd/trunk@7075 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-12-06 23:01:28 +00:00
Qball Cow
e1571cc705 Re-enable seeking in http streams.
Fixing stopping mpd from block when trying to stop a ogg stream that is buffering.


git-svn-id: https://svn.musicpd.org/mpd/trunk@7053 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-11-28 14:06:03 +00:00
Qball Cow
4447ce5065 Don't try to forever to get data when the sockets winds up in "temporary
unavailable" when streaming music. But give up after 100 times. This is
atm better then waiting until the connection gets back, because mpd
blocks on this.


git-svn-id: https://svn.musicpd.org/mpd/trunk@7052 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-11-28 14:00:56 +00:00
Avuton Olrich
5e085751f5 A better way to do the last patch (extremely minor patch)
git-svn-id: https://svn.musicpd.org/mpd/trunk@7042 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-11-21 14:02:03 +00:00
Avuton Olrich
6f11941e5e Fix Sun C 5.9 / C99 compatiblity
git-svn-id: https://svn.musicpd.org/mpd/trunk@7041 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-11-21 13:43:37 +00:00
Qball Cow
6050541d97 When parsing id3_frames take in account that there are different frames
and with different field types.
This fixes comments for id3v1 and id3v2


git-svn-id: https://svn.musicpd.org/mpd/trunk@7040 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-11-21 12:15:00 +00:00
Qball Cow
b8dfe42342 Disable seeking on streams, because of bug 1611. When playing ogg, the decoder seeks through the file then starts to play. This does not mix well with streams from websites. Stopping playback of an oggstream that is trying to stream will result in mpd hanging.
git-svn-id: https://svn.musicpd.org/mpd/trunk@7039 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-11-18 19:15:10 +00:00
Qball Cow
ec49c1d3d9 Fix wavpack endian issues, tested to work for 16bit. (after blowing my ears off with white noise)
git-svn-id: https://svn.musicpd.org/mpd/trunk@6952 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-10-03 16:11:01 +00:00
Qball Cow
cb9d1b3d27 Playlist queue patch (http://musicpd.org/mantis/view.php?id=1478) version 11.
This adds the following commands:
* queueid <id>		Add song <id> to the queue.
* dequeue <pos>		Remove song from <pos> from the queue
* queueinfo			List the queue

To the statusfield it adds the following entry:
playlistqueue:	<uid>		UID can be used by clients to track changes in the playlist queue.



git-svn-id: https://svn.musicpd.org/mpd/trunk@6927 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-26 08:25:35 +00:00
Eric Wong
3a03b89b48 inputPlugins/_ogg_common.c: fixup includes for new (1.1.4+ FLAC)
ogg_stream_type_detect may not be compiled correctly
when compiling FLAC (1.1.4+) without Vorbis

git-svn-id: https://svn.musicpd.org/mpd/trunk@6896 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-17 11:30:37 +00:00
Avuton Olrich
1337f33c62 Add oga extension for flac-1.2.1
git-svn-id: https://svn.musicpd.org/mpd/trunk@6888 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-14 22:15:38 +00:00
Eric Wong
34f3abd357 conf.c: remove extra semi-colon here, too
git-svn-id: https://svn.musicpd.org/mpd/trunk@6874 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-10 07:15:58 +00:00
Eric Wong
8b141ae54e buffer input while waiting for outputBuffer space in mp4 and (ogg)flac
Both mp4 and (ogg)flac inputPlugins got HTTP inputStream support
later in the game, so their calls to sendDataToOutputBuffer()
didn't get updated to support buffering while the outputBuffer
was full.  This fixes it.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6873 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-10 07:12:42 +00:00
Eric Wong
54339dfbc2 pcm_utils: gcc 2.95 compile fix (extra semi-colon)
git-svn-id: https://svn.musicpd.org/mpd/trunk@6872 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-10 07:12:37 +00:00
Eric Wong
38de8d0808 playerInit() is static
git-svn-id: https://svn.musicpd.org/mpd/trunk@6868 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-08 03:29:13 +00:00
Eric Wong
30ed6bcf22 inputStream_http: signal the server to close after all requests
We want the partial content goodies of HTTP/1.1 without
requiring persistent connections.  Persistent connections across
multiple HTTP requests don't really help in the case of MPD,
either, because our content is usually big and heavy.

Note: this puts MPD at the hands of the server to correctly
close() the TCP connection we're using.  If we connect to a
rogue server that keeps the connection alive even when request
not to, we'll spin :(  However, encountering such a server
is very unlikely...

git-svn-id: https://svn.musicpd.org/mpd/trunk@6867 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-08 01:06:29 +00:00
Eric Wong
251216a552 decode: fix seek when paused
We need to SIGCONT the decoder process to allow for seeking
while paused.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6864 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-07 01:17:09 +00:00
Eric Wong
45c9989849 get rid of unused DECODE_SUFFIX_* #defines
These haven't been used for several years

git-svn-id: https://svn.musicpd.org/mpd/trunk@6863 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-07 00:59:29 +00:00
Eric Wong
56274fd016 Once again get rid of busy waiting and use SIGSTOP for pause
The problems I had were related to the OSS driver and USB
device I was using.  The problems existed even with the old
busy-waiting scheme enabled.

OSS  - Bithead USB     => bad
ALSA - Bithead USB     => OK
OSS  - Onboard i8x0    => OK
ALSA - Onboard i8x0    => OK

bad - slow shutdown, pauses, dropped audio after pause/resume

git-svn-id: https://svn.musicpd.org/mpd/trunk@6861 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-06 01:07:49 +00:00
Eric Wong
7024700cc5 return to busy-waiting on pause for now..
Until we can fix it properly (or replace it with a cleaner event
system), I don't want this in trunk.  Currently there are
strange pauses when queueing and during shutdown that I can't
seem to figure out right away.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6860 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-06 00:45:34 +00:00
Eric Wong
fe584bb11c send SIGCONT to the player process whenever we need to busy wait on it
This fixes the problem of playlist moving/changnig while we're paused

Followup to r6822

git-svn-id: https://svn.musicpd.org/mpd/trunk@6859 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-06 00:19:33 +00:00
Eric Wong
b2ae8da509 conf: use getBoolBlockParam for block params, too
git-svn-id: https://svn.musicpd.org/mpd/trunk@6858 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-05 23:59:36 +00:00
Eric Wong
4a2122eaf4 conf: improved boolean config parameter handling from -ke
the force flag will issue FATAL() if an invalid value is
specified

git-svn-id: https://svn.musicpd.org/mpd/trunk@6857 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-05 23:59:33 +00:00
Eric Wong
ac58dce7df Redirect stdin *before* we establish a listen socket
This way we'll avoid listening on fd=0 and have a better
chance of having fd=0 as /dev/null

git-svn-id: https://svn.musicpd.org/mpd/trunk@6852 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-05 01:19:37 +00:00
Eric Wong
7992ff37d0 log: oops, fix a syntax error
(yes, it helps to actually compile code before committing it)

git-svn-id: https://svn.musicpd.org/mpd/trunk@6851 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-04 21:08:35 +00:00
Eric Wong
146485d0cb log: better bug avoidance for libraries incorrectly handling fd=0
We redirect stdin to /dev/null to work around a libao bug, but
this bug has been fixed in libao since 2003 (according to jat).

However, there are likely other bugs in other libraries (and
even our code!) that handle fd=0 incorrectly and I'd rather not
take the risk[1].  So So it's easiest to just keep
fd=0==/dev/null for now...

[1] - I've seen several of these myself...

git-svn-id: https://svn.musicpd.org/mpd/trunk@6849 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-04 19:45:24 +00:00
Eric Wong
203a5ed26d zeroconf: avoid passing NULLs to Avahi *_free() routines
This should fix Debian bug #428551
(mpd crashes when restarting the dbus daemon)

git-svn-id: https://svn.musicpd.org/mpd/trunk@6844 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-02 02:18:09 +00:00
Eric Wong
bbe8b0efd8 Fix endless loop when mpd is launched from a non-interactive shell.
Thanks to _noth_ for the patch, this fixes Mantis bug #1534

_noth_ wrote:
> When MPD is launched from a non-interactive shell, it enters an endless
> loop, filling up its error log file with "error accept()'ing" messages.
> This is caused by the fact that stdin is already closed when mpd starts
> up.  listenOnPort() opens up the first of its sockets as fd 0 (the first
> empty fd table position). Then, setup_log_output()->redirect_stdin()
> overwrites fd0 (fd=open("/dev/null",...); dup2(fd, STDIN_FILENO);)
> without checking if it corresponds to the actual standard input (or if
> it is open in the first place).  This means that listenSockets[0].fd now
> is a fd for /dev/null, thus doIOForInterfaces()->getConnections() can't
> accept(2) on it and fails with the above error. The attached patch fixes
> this for me.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6843 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-02 01:11:28 +00:00
Eric Wong
c2e742106f interface: fix IPV6 hostname buffer deallocation from automatics
The host buffer that hostname pointed to is no longer on the
stack by the time the SECURE() message is printed.  So make it
static and thus accessible to all.  We won't be calling this
stuff in the middle of a child process/thread/task, so there's
no

Also, hostname is a constant string we shouldn't modify, so mark
it as const char *.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6842 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-01 12:20:49 +00:00
Eric Wong
c5c8548ba2 inputPlugins/flac: improve error messages
For the default: case, just use the error message that libFLAC
provides instead of using something ambiguous.  Also, this gets
rid of long lines in the code, making it easier to digest.

Of course, we save ~100 bytes of text space in the process :)

git-svn-id: https://svn.musicpd.org/mpd/trunk@6830 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-28 05:01:19 +00:00
Eric Wong
cd6e584c35 log: cleanup: avoid "magic" numbers
We used a bare '15' in several places and it's not immediately
obvious where it came from.  This makes it more obvious

git-svn-id: https://svn.musicpd.org/mpd/trunk@6829 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-28 05:01:16 +00:00
J. Alexander Treuman
1b045d0672 removing debug messages from signal handlers
As unfortunate as it is to remove such useful debugging messages, it's
necessary to fix a potential deadlock with signal handling.  A bunch of
functions the debug functions call aren't safe to call from a signal
handler.  There are some alternate solutions, but they're neither pretty
nor simple.  So just remove them entirely for now.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6828 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-27 21:18:35 +00:00
J. Alexander Treuman
752bf24b74 interface: print whole debug message at once
Using SECURE once without a \n, and again with one, results in a timestamp
mid-line.  Let's not do that.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6827 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-27 21:10:44 +00:00
J. Alexander Treuman
8d89add8e7 adding \n to a bunch of error message strings
git-svn-id: https://svn.musicpd.org/mpd/trunk@6826 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-27 21:03:22 +00:00
Eric Wong
f18e524176 send SIGSTOP to player and decoder processes on pause, too
as with the stop command, this will cause the player and decoder
to suspend and not wake up hundreds of times a second to poll
a variable for wakeup.  This will reduce power consumption
on some CPUs while mpd is paused and not playing.

tests:

pause && unpause => OK

pause && stop && play => OK

pause && exit && restart w/statefile && unpause => OK

pause && block sound device && \
unpause => failed to open sound device \
=> still paused and suspended => unblock sound device &&
unpause => OK (playing)

In all cases, the player process releases the audio device
when paused before going into the suspended state.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6822 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-27 09:36:11 +00:00
Eric Wong
0f2e9ee662 export FATAL() with noreturn attribute
This attribute was set in log.c, but not exported to other
modules in log.h

This allows us to remove some unneccessary variable
initializations that were added in r6277.  I did
audioOutput_shout.c a bit differently, to avoid some
jumps.

before:
$ size src/mpd
text    data     bss     dec     hex filename
225546    4040   14600  244186   3b9da src/mpd

after:
$ size src/mpd
text    data     bss     dec     hex filename
224698    4040   14600  243338   3b68a src/mpd

git-svn-id: https://svn.musicpd.org/mpd/trunk@6821 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-27 08:05:55 +00:00
J. Alexander Treuman
fe4b16ed96 inputPlugins/mp3_plugin: parse LAME tags for ReplayGain info
Parse ReplayGain info in LAME tags and use it if no ID3v2 ReplayGain tags
are found.  This is currently a bit unsafe, as apparently some LAME tags
have bogus ReplayGain values.  But I'm finding a lot of MP3s with valid
LAME tags that fail the LAME tag CRC check.  So until I figure out why
that's happening, it's an unreliable method for checking if the LAME tag is
valid.

A big thanks to tmz for writing the original patch.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6798 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-22 16:42:08 +00:00
J. Alexander Treuman
5e1deab05f decode: close audio device after initial open if paused
Currently, if we start decoding while the pause flag is set, we open the
audio device and leave it opened, blocking other apps from using it.  The
obvious thing to do is to not open the audio device if the pause flag is
set, but the open call also sets the audio format.  Therefore I'm leaving
the open call in, and just closing it immediately afterwards if the pause
flag is set.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6745 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-12 19:23:48 +00:00
J. Alexander Treuman
d286294805 decode: reformatting for better readability
git-svn-id: https://svn.musicpd.org/mpd/trunk@6742 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-12 19:15:06 +00:00
J. Alexander Treuman
3fedc4d806 audioOutputs/audioOutput_shout: adding timers back
The shout plugin will now feign playback until the connect timeout is hit,
preventing connection attempts from blocking playback on local outputs.
Note that this patch is very different from remiss' original one.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6738 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-11 21:36:23 +00:00
Qball Cow
e195fb8100 Cleanup a outcommented debug statement
git-svn-id: https://svn.musicpd.org/mpd/trunk@6736 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-08-11 11:36:13 +00:00
Qball Cow
4811eadb4a Extra debug output
git-svn-id: https://svn.musicpd.org/mpd/trunk@6689 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-07-16 20:31:37 +00:00
J. Alexander Treuman
54e6b27989 log: flush the warning log after redirecting stderr to the log files
Previously, the warning log was only flushed if creating the db or logging
to stdout.  This meant that under normal circumstances (no db creation,
logging to files) the warning log was never flushed.  This caused a bug
when a warning was printed for each call to the status command where the
warning buffer would grow endlessly, eventually using more and more CPU to
reallocate it.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6660 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-06-29 18:41:02 +00:00