Commit Graph

2198 Commits

Author SHA1 Message Date
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