Commit Graph

1906 Commits

Author SHA1 Message Date
Max Kellermann
ad92d9a894 command: fix command "addid"
With patch 8d2830b3, I broke "addid": it did not return the id of the
new song, because of a typo in the return condition (== instead of
!=).
2008-09-23 23:59:55 +02:00
Max Kellermann
d42959c5ce flac: removed FlacData.chunk_length
chunk_length can be converted to a local variable, because it is
always reset to 0 after it was used.
2008-09-23 23:59:55 +02:00
Max Kellermann
0c934f9d36 flac: merged flacSendChunk() into flac_common_write()
Since flacSendChunk() is a trivial function and is only used in one
location, move the code there.  The advantage is that calling
decoder_data() directly returns the decoder_command value, so we can
eliminate one decoder_get_command() call.
2008-09-23 23:59:55 +02:00
Max Kellermann
eeb3011070 flac: removed generic sample size support
Support for bit rates except 16 bits (and 8 bits on little endian) has
always been broken.  Since we added optimized functions for 8, 16,
24/32 bits, we can remove the generic flac_convert() function.
Instead of removing it, convert it to a wrapper function for
flac_convert_*().
2008-09-23 23:59:55 +02:00
Max Kellermann
19971be307 flac: added special functions for 8 and 32 bit
Same optimization for 8 and 32 bit files, like the previous patch for
16 bit.  Along the way, this patch adds 24 bit FLAC support!
2008-09-23 23:59:55 +02:00
Max Kellermann
8c2bde70b0 flac: added optimized converter for 16 bit
flac_convert_16() runs a lot faster than the generic (and quite buggy)
function flac_convert().  flac_convert_16() is only used for
non-stereo files, since there is already flac_convert_stereo16().
2008-09-23 23:59:55 +02:00
Max Kellermann
7486c15088 flac: use signed integers in flac_convert_stereo16()
By mistake, I casted the sample value to uint16_t, which is wrong.
This patch simplifies the code by using a int16_t pointer instead of
casting to int16_t* every time.
2008-09-23 23:59:54 +02:00
Max Kellermann
8bcbe90b25 flac: moved code from flacWrite() to _flac_common.c
There is still a lot of duplicated code in flac_plugin.c and
oggflac_plugin.c.  Move code from flac_plugin.c to _flac_common.c, and
use the new function flac_common_write() also in oggflac_plugin.c,
porting lots of optimizations over to it.
2008-09-23 23:59:54 +02:00
Max Kellermann
aac5f42698 flac: assume the buffer is empty in flacWrite() II
The previous patch on this topic was incomplete: it still added
data->chunk_length when calling flac_convert().  Remove this, too.
2008-09-23 23:59:54 +02:00
Max Kellermann
128d8c7c15 audio_format: added audio_format_sample_size()
The inline function audio_format_sample_size() calculates how many
bytes each sample consumes.  This function already takes into account
that 24 bit samples are 4 bytes long, not 3.
2008-09-23 23:59:54 +02:00
Eric Wong
e4f5d6bdf4 alsa: re-enable-nonblocking, but sleep if busy
Instead of letting ALSA block for us (and potentially allowing
something stupid on certain hardware or drivers), we do the
sleeping ourselves.  We calculate the sleep to be a fraction of
period_time to avoid oversleeping (and thus audible skipping).
2008-09-23 23:59:54 +02:00
Eric Wong
ef35926083 songvec: avoid free(NULL)
Potentially broken free() implementations don't like it
2008-09-23 22:38:43 +02:00
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