Commit Graph

2427 Commits

Author SHA1 Message Date
Max Kellermann
6bbea44e91 output: call send_tag() only if device is on
Why send tags to a device which isn't enabled?
2008-09-24 07:21:58 +02:00
Max Kellermann
5cf6213344 output: document the audio_output_plugin methods 2008-09-24 07:21:51 +02:00
Max Kellermann
08352184ac output: document the audio_output elements 2008-09-24 07:21:46 +02:00
Max Kellermann
acc4a0ba2d output: make "struct audio_output" opaque for output plugins
We have eliminated direct accesses to the audio_output struct from
the all output plugins.  Make it opaque for them, and move its real
declaration to output_internal.h, similar to decoder_internal.h.

Pass the opaque structure to plugin.init() only, which will return the
plugin's data pointer on success, and NULL on failure.  This data
pointer will be passed to all other methods instead of the
audio_output struct.
2008-09-24 07:20:55 +02:00
Max Kellermann
63fb1efb5c output: added audio_output_closed()
The JACK output plugin needs to reset its "opened" flag when the JACK
server fails.  To prevent it from accessing the audio_output struct
directly introduce the API function audio_output_closed().
2008-09-24 07:20:37 +02:00
Max Kellermann
3be5db0430 output: added audio_output_get_name()
Reduce direct accesses to the audio_output struct from the plugins:
this time, eliminate all accesses to audio_output.name.  The name is
required by some plugins for log messages.
2008-09-24 07:20:37 +02:00
Max Kellermann
2403d32a50 output: set audio_output->open=1 in audio_output_task()
Since the output plugin returns a value indicating success or error,
we can have the output core code assign the "open" flag.
2008-09-24 07:20:36 +02:00
Max Kellermann
3cae6856b8 output: pass audio_format to plugin.init() and plugin.open()
Pass the globally configured audio_format as a const pointer to
plugin.init().  plugin.open() gets a writable pointer which contains
the audio_format requested by the plugin.  Its initial value is either
the configured audio_format or the input file's audio_format.
2008-09-24 07:20:36 +02:00
Max Kellermann
d32f49a90b output: one thread per audio output
To keep I/O nastiness and latencies away from the core, move the audio
output code to a separate thread, one per output.  The thread is
created on demand, and currently runs until mpd exits.
2008-09-24 07:20:26 +02:00
Max Kellermann
8f4ebf0caf notify: added macro NOTIFY_INITIALIZER
With the macro NOTIFY_INITIALIZER, you can statically initialize a
notify object.
2008-09-24 07:16:59 +02:00
Max Kellermann
a0272c2d61 notify: added notify_deinit()
Destroy the mutex when it is not used anymore.
2008-09-24 07:14:11 +02:00
Max Kellermann
ee1d723ad7 notify: make notify_init() failures fatal
When a mutex cannot be created, there must be something very wrong.
Induce panic and abort MPD in this case.
2008-09-24 07:14:03 +02:00
Max Kellermann
770b140534 notify: declare "struct notify"
"struct notify" is the same as the "Notify" typedef.  It can be
forward-declared and has a lower case name.
2008-09-24 07:05:43 +02:00
Max Kellermann
35216db8db doc/COMMANDS: document "addid" 2008-09-23 23:59:55 +02:00
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
Max Kellermann
9899ab5ac2 properly configure the M4 macro directory
Add information about the M4 macro dir ./m4/ to both configure.ac and
Makefile.am.
2008-09-23 22:38:46 +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