Commit Graph

2501 Commits

Author SHA1 Message Date
Max Kellermann
cd7a720426 ffmpeg: simplified mpdurl_read()
The function mpdurl_read() is too complicated, and uses the wrong data
types.
2008-10-30 19:02:01 +01:00
Max Kellermann
964442c5ad ffmpeg: call tag_free() instead of free()
tag objects must be freed with tag_free() to ensure that all resources
are freed.
2008-10-30 19:01:36 +01:00
Max Kellermann
25f4efcdb8 ffmpeg: eliminated local variable "tag"
The function ffmpeg_tag() already has the variable base.tag, which can
be used for this.
2008-10-30 19:01:31 +01:00
Max Kellermann
7cbd9821c6 ffmpeg: make ffmpeg_helper() return bool
ffmpeg_try_decode() did not interpret ffmpeg_helper()'s return value
properly; migrate everything to bool to make it consistent.
2008-10-30 19:01:23 +01:00
Max Kellermann
078d83ca13 ffmpeg: removed debug messages
We don't need those anymore, they just fill the log.
2008-10-30 19:01:18 +01:00
Max Kellermann
b180d0b47f ffmpeg: initialize base.decoder
ffmpeg_tag() did not initialize base.decoder, which made valgrind
unhappy, and can lead to a egmentation fault.
2008-10-30 18:08:52 +01:00
Max Kellermann
4d72bda4c3 listen: set file mode 666 on the unix socket
Depending on MPD's umask, the file permissions of the unix socket were
too restrictive, and many clients were not able to connect.  Do a
chmod(0666) on the socket, to allow everybody to connect.
2008-10-30 18:03:18 +01:00
Max Kellermann
9ec695559f pulse: fix segfault without sink name
Commit d692e9 broke configurations without explicit server or sink
configuration.  Check for getBlockParam()==NULL.
2008-10-30 17:46:56 +01:00
Max Kellermann
5f6383d68c mpc: provide 24 bit samples
Similar to libmad, libmpcdec provides samples with higher quality than
16 bit.  Send 24 bit samples to MPD, which allows MPD to apply
dithering just in case the output devices are only 16 bit capable.
2008-10-30 08:45:00 +01:00
Max Kellermann
0db07a920e mpc: moved sample size into a constant
Don't hard-code the "16 bits" or "2 bytes" in multiple locations.
2008-10-30 08:44:51 +01:00
Max Kellermann
6773dea5b0 mpc: renamed variable "s16" to "dest"
The name "s16" implies 16 bit integers.  To make the code more
generic, rename it to "dest".
2008-10-30 08:44:43 +01:00
Max Kellermann
51348d6992 mpc: fix broken integer sample conversion
The conversion of integer samples was completely broken, which
presumably didn't annoy anybody because libmpcdec provides float
samples on most installations.
2008-10-30 08:44:28 +01:00
Max Kellermann
ecd485acbd mpc: fix boolean interpretation of input_stream_seek()
When input_stream_seek() was converted to return a bool, this wasn't
adjusted in the musepack plugin.
2008-10-30 08:42:18 +01:00
Max Kellermann
62d4fa9306 decoder: use bool for return values and flags
Don't return 0/-1 on success/error, but true/false.  Instead of int,
use bool for storing flags.
2008-10-30 08:38:54 +01:00
Max Kellermann
d29bad4410 mp3: make mp3_read() return bool
Its only caller in mp3_decode() just compared its value with
DECODE_BREAK.  Convert that to bool, and return false if the loop
should be ended.  Also eliminate some superfluous command checking
code, which was already done in the preceding while loop.
2008-10-30 06:09:28 +01:00
Max Kellermann
f8722913cf output: removed audio_output.result
Since open() and play() close the device on error, we can simply check
audio_output.open instead of audio_output.result after a call.
2008-10-29 22:34:37 +01:00
Max Kellermann
7da0e005f3 output: delay reopen after device failure
When one of several output devices failed, MPD tried to reopen it
quite often, wasting a lot of resources.  This patch adds a delay:
wait 10 seconds before retrying.  This might be changed to exponential
delays later, but for now, it makes the problem go away.
2008-10-29 22:32:50 +01:00
Max Kellermann
0eae1c55ad output: moved code to audio_output_update()
Moved code from syncAudioDeviceStates() to audio_output_update().
2008-10-29 22:17:44 +01:00
Max Kellermann
678314534a output: always call cancel() before stop()
Stopping an audio output device without cancelling its buffer doesn't
make sense.  Combine the two operations, which saves several cancel
calls.
2008-10-29 22:17:42 +01:00
Max Kellermann
07bb46de88 input_file: refuse to open non-regular files
Don't allow users to open a file which is non-regular (e.g. pipes,
devices).
2008-10-29 21:11:28 +01:00
Max Kellermann
84f7d9c6b3 input_file: check fstat() failure 2008-10-29 21:11:20 +01:00
Max Kellermann
fb08213659 input_file: use GLib for logging 2008-10-29 21:11:04 +01:00
Max Kellermann
8f3d962219 log: don't use utils.h
Prefer GLib over utils.h.
2008-10-29 21:02:22 +01:00
Max Kellermann
cf376b4bc8 output: moved audioDeviceStates to audio_output.enabled 2008-10-29 20:49:51 +01:00
Max Kellermann
2f76db4c78 output: close device on play error
When an output plugin fails to play a chunk, close it.  This replaces
various manual close() calls in nearly all plugins.
2008-10-29 20:40:33 +01:00
Max Kellermann
58c5bee9f0 output: use bool for return values and flags
Don't return 0/-1 on success/error, but true/false.  Instead of int,
use bool for storing flags.
2008-10-29 20:40:27 +01:00
Max Kellermann
03390d8be1 audio: call closeAudioDevice() on error
Instead of implementing another loop which calls audio_output_close()
on all configured devices, simply call closeAudioDevice().
2008-10-29 20:39:56 +01:00
Max Kellermann
030238bb10 audio: removed variable "audioOpened"
This variable is never read, and can be removed.
2008-10-29 20:39:48 +01:00
Max Kellermann
b967702059 pulse: clear pa_simple pointer in pulse_close()
The pointer becomes invalid due to pa_simple_free(), which may lead to
segmentation faults when the output is reopened later.
2008-10-29 20:38:20 +01:00
Max Kellermann
d692e925a4 pulse: use GLib instead of util.h/log.h
Use GLib allocation and logging functions.
2008-10-29 20:37:36 +01:00
Max Kellermann
38df17546a pulse: no CamelCase 2008-10-29 20:37:15 +01:00
Max Kellermann
2867c8e9b1 player: handle songs shorter than the initial buffer
When the decoder exited before the buffer has grown big enough
("buffer_before_play"), the player thread waited forever.  Add an
additional check which disables buffering as soon as the decoder
exits.
2008-10-29 18:35:10 +01:00
Max Kellermann
5c4dc8d03c oss: check and override audio_format properly
Don't accept 24 bit audio.  Force MPD to use 16 bit if anything other
than 8 or 16 bit is selected.
2008-10-29 18:35:03 +01:00
Max Kellermann
c6714f1755 player: added variable "play_audio_format"
The local variable "play_audio_format" is updated every time the
player starts playing a new song.  This way, we always know exactly
which audio format is current.  The old code broke when a new song had
a different format: ob.audio_format is the format of the next song,
not of the current one - using this caused breakage for the software
volume control.
2008-10-29 17:29:30 +01:00
Max Kellermann
528b7c3f5e decoder: automatically flush the output buffer after decoder exits
A decoder_flush() invocation was missing in the FLAC plugin, resulting
in casual assertion failures due to a wrong assumption about the last
chunk's audio format.  It's much easier to remove that decoder_flush()
function and make the decoder thread call ob_flush().
2008-10-29 17:29:06 +01:00
Max Kellermann
74c85811af decoder_api: make the audio_format parameter mandatory
There are no callers which pass audio_format==NULL, and it shouldn't
be allowed.
2008-10-29 17:29:03 +01:00
Max Kellermann
c042faab42 player: request new song only if there is no pending command
Request the next song from the playlist (by clearing pc.next_song)
only if the player command is empty.  If it is not, the player may be
clearing the song that has already been queued, leading to an
assertion failure.
2008-10-29 17:28:49 +01:00
Max Kellermann
be90199c5a decoder_api: removed decoder_clear()
Call ob_clear() in decoder_command_finished() instead of implementing
that call in every decoder plugin.
2008-10-29 17:28:47 +01:00
Max Kellermann
d6c4441c78 mp3: seek in background
Remember the seek_where argument and call decoder_command_finished()
immediately.  This way, the player thread can continue working, and we
can receive more commands.

This also fixes several issues which resulted in broken frames,
leading to erroneos "elapsed" values: frames weren't parsed properly,
since the code was checking for command!=NONE.
2008-10-29 17:22:56 +01:00
Max Kellermann
de588448df mp3: return from mp3_synth_and_send() on any command
Previously, the function would only return when a STOP was issued.  It
makes more sense to consider all possible commands.
2008-10-29 16:17:21 +01:00
Max Kellermann
6158858f82 mp3: moved code to mp3_synth_and_send()
Break the large function mp3_read() into smaller pieces.
2008-10-29 16:14:08 +01:00
Max Kellermann
e0532ae0a8 mp3: moved code to mp3_send_pcm()
Break the large function mp3_read() into smaller pieces.
2008-10-29 16:14:02 +01:00
Max Kellermann
a6ad0e4047 mp3: moved code to mp3_update_timer_next_frame()
Break the large function mp3_read() into smaller pieces.
2008-10-29 16:13:51 +01:00
Max Kellermann
0d079ee515 mp3: moved code to mp3_this_frame_offset()
Break the large function mp3_read() into smaller pieces.
2008-10-29 16:13:01 +01:00
Max Kellermann
a6f8776c94 mp3: moved code to mp3_time_to_frame()
Break the large function mp3_read() into smaller pieces.
2008-10-29 16:12:26 +01:00
Max Kellermann
ec3083948f mp3: assert that the stream is seekable
dc_seek() won't send a SEEK command to the decoder thread unless the
stream is seekable.  No need to do another check; convert that to an
assertion.
2008-10-29 16:11:16 +01:00
Max Kellermann
78b08f03f2 decoder_api: don't cast need_chunks() to int
need_chunks() returns a decoder_command enum.  Store its return value
as this type.
2008-10-29 16:11:15 +01:00
Max Kellermann
a0b57f3782 mp3: moved code to mp3_filesize_to_song_length()
The function mp3_decode_first_frame() is too large.  Move some code to
separate smaller functions.
2008-10-28 20:44:08 +01:00
Max Kellermann
898978a67d mp3: no "goto"
http://xkcd.com/292/
2008-10-28 20:43:17 +01:00
Max Kellermann
28b47725ff mp3: use GLib allocation functions
This removes the need for util.h.
2008-10-28 20:43:15 +01:00
Max Kellermann
56ebdf1cd1 mp3: use bool
Use the C99 bool data type for boolean values.
2008-10-28 20:42:33 +01:00
Max Kellermann
e4bbc120ac mp3: no CamelCase
Renamed all functions and variables.  Also removed the mp3DecodeData
typedef.
2008-10-28 20:42:01 +01:00
Max Kellermann
1f7c53e619 mp3: remove obsolete comments 2008-10-28 20:41:25 +01:00
Max Kellermann
25f98a41c4 input_file: don't use buffered I/O
Yet another superfluous buffering layer.  input_file was using FILE*,
but we're better off with unbuffered I/O using open(), read(), ...
2008-10-28 20:41:24 +01:00
Max Kellermann
0a61877702 input_stream: convert offset and size to the off_t data type
size_t and long aren't 64 bit safe (i.e. files larger than 2 GB on a
32 bit OS).  Use off_t instead, which is a 64 bit integer if compiled
with large file support.
2008-10-28 20:39:09 +01:00
Max Kellermann
016d996131 utils: use g_str_has_prefix() instead of prefixcmp()
Remove duplicated code from MPD.
2008-10-28 20:33:56 +01:00
Max Kellermann
4a71f66256 player: reset pc.command when decoder startup fails
When the decoder failed to start, the function do_play() returned,
still having pc.command==PLAY.  This is because pc.command was reset
only when the decoder started up successfully.  Add another
player_command_finished() call in the error handler.
2008-10-27 10:10:40 +01:00
Max Kellermann
0d30d51f07 input_file, input_curl: check URL type before attempting to open
Don't attempt to open a HTTP URL as a local file, and don't send a
local path to libcurl.
2008-10-27 10:10:24 +01:00
Max Kellermann
0800c6f4ca output: don't compile plugins which are disabled
Don't compile the sources of disabled output plugins at all.
2008-10-26 21:58:37 +01:00
Max Kellermann
3dac99034a dirvec: fixed GCC shadow warning
On some systems, string.h declares basename().  This emits a shadow
warning.  Change the variable name.
2008-10-26 21:28:16 +01:00
Max Kellermann
5f2384001e curl: read stream name from HTTP response headers
If the server sends the headers "icy-name", "ice-name",
"x-audiocast-name", set the stream title.
2008-10-26 21:20:02 +01:00
Max Kellermann
5d9ef0cd83 input_curl: set input_stream.mime from Content-Type response header 2008-10-26 21:19:32 +01:00
Max Kellermann
1437a56a11 input_curl: added local variable "value"
Replaced the local variable "colon" (which had only temporary meaning)
with the variable "value".  It is a pointer to the first byte of the
header value.
2008-10-26 21:12:56 +01:00
Max Kellermann
d401589edf input_stream: use g_free() in input_stream_close()
g_free() allows passing the NULL pointer.
2008-10-26 21:02:49 +01:00
Max Kellermann
5c19776f2f input_stream: use "bool" instead of "int"
For boolean values and success flags, use bool instead of integer (1/0
for true/false, 0/-1 for success/failure).
2008-10-26 20:56:46 +01:00
Max Kellermann
464b611772 input_stream: input_stream_close() returns void
close() shouldn't fail with read-only streams.
2008-10-26 20:54:52 +01:00
Max Kellermann
f08041f0eb input_stream: added struct input_plugin
Instead of managing a set of method pointers in each input_stream
struct, move these into the new input_plugin struct.  Each
input_stream has only a pointer to the plugin struct.  Pointers to all
implementations are kept in the array "input_plugins".
2008-10-26 20:38:44 +01:00
Max Kellermann
dbc7e9ba2f input_stream: no CamelCase
Renamed all functions and variables.
2008-10-26 20:34:47 +01:00
Max Kellermann
97a9c7a8e0 input_file: removed global constructor
The global constructor is empty, and can be removed.
2008-10-26 20:34:33 +01:00
Max Kellermann
23552f89cc input_file: don't export internal methods
The methods are only used in inputStream_fileOpen(), and should not be
exported.
2008-10-26 20:34:03 +01:00
Max Kellermann
21b8590b53 input_stream: removed the InputStream typedef
Everybody should use struct input_stream.
2008-10-26 19:54:57 +01:00
Max Kellermann
bbaedb17d5 input_stream: renamed sources, no CamelCase
Renamed inputStream.c and inputStream_file.c.
2008-10-26 19:38:50 +01:00
Max Kellermann
3609de8685 http: use libcurl
MPD's HTTP client code has always been broken, no matter how effort
was put into fixing it.  Replace it with libcurl, which is known to be
quite stable.  This adds a fat library dependency, but only for people
who need streaming.
2008-10-26 19:32:43 +01:00
Max Kellermann
6b09e4daef input_stream: added input_stream_global_finish()
The hook input_stream_global_finish() deinitializes global structures
of all input stream implementations.
2008-10-26 19:30:13 +01:00
Max Kellermann
4bc2def15c stored_playlist: fixed signed comparison warning
Cast playlist_max_length to off_t before comparing it to stat.st_size.
2008-10-26 16:26:44 +01:00
Max Kellermann
4fa36a15bf command: removed range check from check_bool()
check_bool() accepts only "0" or "1".  The range check is superfluous.
2008-10-26 16:19:33 +01:00
Max Kellermann
ece8c1347c renamed src/audioOutputs/ to src/output/
Again, no CamelCase in the directory name.
2008-10-26 11:29:44 +01:00
Max Kellermann
e11355f47d renamed src/inputPlugins/ to src/decoder/
These plugins are not input plugins, they are decoder plugins.  No
CamelCase in the directory name.
2008-10-26 11:29:25 +01:00
Max Kellermann
1110a6d410 removed internal copy of libmp4ff
MPD shouldn't integrate sources of other libraries.  Since libmp4ff is
part of libfaad, we should remove the old copy from src/mp4ff and link
with the current version from libfaad instead.
2008-10-25 20:59:36 +02:00
Max Kellermann
a02db57291 pulse: force 16 bit audio sample format
PA_SAMPLE_S16NE is the only sample format which is suported by both
MPD and pulseaudio.  Unfortunately, pulse does not accept 24 bit
samples.

Instead of bailing out with an error message, we should tell the MPD
core to convert all samples to 16 bit for pulse.
2008-10-25 20:41:28 +02:00
Max Kellermann
ee499cb42f player: don't clear command before do_play() returns
This bug caused the audio output devices to stay open, although MPD
wasn't playing: quitDecode() resetted player_control.command, assuming
that the command was STOP.  This way, player_task() didn't see the
CLOSE_AUDIO command, and the device was kept open.

Don't clear player_control.command in quitDecode().
2008-10-24 17:50:24 +02:00
Max Kellermann
18c6ebb023 remove unused sources
These are results from failed merges which I didn't notice.
2008-10-24 17:41:13 +02:00
Max Kellermann
f4e6bb2815 jack: support for 24 bit samples
When the audio source provides 24 bit samples, don't bother to convert
(lossily) them to 16 bit before jack's floating point conversion - go
directly from 24 bit to float.
2008-10-24 17:36:11 +02:00
Max Kellermann
b1adfaae43 jack: moved code to jack_write_samples_16()
Move sample format dependent code to a separate function.
2008-10-24 17:34:47 +02:00
Max Kellermann
03a077e8a4 jack: eliminated CamelCase
Renamed all variables and functions.  Add the prefix "mpd_jack_" to
function names.
2008-10-24 17:29:37 +02:00
Max Kellermann
e19f0a8dbc jack: added assertions against partial frames
We must never pass partial frames.  Added assertions to debug this.
2008-10-24 16:56:10 +02:00
Max Kellermann
e7cd237674 jack: optimize local variables
Merge the variables "avail_data" and "avail_frames" into "available".
Both variables are never used at the same time.
2008-10-24 16:56:08 +02:00
Max Kellermann
0a6704420b jack: lockless data transfer to jack thread
The JACK documentation postulates that the process() callback must not
block, therefore locking is forbidden.  Anyway, the old code was racy.

Remove all locks, and don't wait for more data to become available -
just send to the port what is already in the buffer.
2008-10-24 16:55:51 +02:00
Max Kellermann
4ecdaabbb0 jack: partial writes to ring buffer
Don't wait until there is room for the full data chunk passed to
jack_playAudio().  Try to incrementally send as much as possible into
the ring buffer.
2008-10-24 16:39:43 +02:00
Max Kellermann
91ad576aad jack: added constant "frame_size"
Don't hard-code a frame size of "4" (16 bit stereo), calculate the
sample size from sizeof(*buffer), and create the constant
"frame_size".
2008-10-24 15:47:52 +02:00
Max Kellermann
9d6651d8b2 jack: fix indentation
Indent with tabs.
2008-10-24 08:44:40 +02:00
Max Kellermann
8b4829c2fe pcm_resample: support for libsamplerate < 0.1.3
libsamplerate 0.1.2 didn't have the 32 bit <-> float conversion
routines.  Emulate them in case they aren't supported.
2008-10-24 08:41:34 +02:00
Max Kellermann
5fefa954a3 player: don't send partial frames of silence
Another partial frame fix: the silence buffer was 1020 bytes, which
had room for 127.5 24 bit stereo frames.  Don't send the partial last
frame in this case.
2008-10-23 20:54:52 +02:00
Max Kellermann
4eadb0f7aa pcm_utils: added 24 bit conversion functions
24 bit output is as important as 16 bit output.  Provide a
pcm_convert() implementation which can convert to 24 bit with as
little quality loss as possible.
2008-10-23 20:11:37 +02:00
Max Kellermann
ec37633f1c pcm_utils: generic pcm_convert_size() implementation
The old pcm_convert_size() ignored most of the destination format,
e.g. it did not check its sample size, and assumed it is 16 bit.
Simplify and universalize it by using audio_format_frame_size().
2008-10-23 20:11:28 +02:00
Max Kellermann
98e4817548 pcm_utils: moved code to pcm_convert_16()
pcm_convert() converted only to 16 bit.  To be able to support other
sample sizes, move that 16 bit specific code to a separate function.
2008-10-23 20:11:24 +02:00
Max Kellermann
8489e90c1e pcm_channels: added 24 bit implementations
The 24 bit implementation is mostly copy'n'paste of the 16 bit
version, except that the data type is int32_t instead of int16_t.
2008-10-23 20:04:37 +02:00
Max Kellermann
a0bcbb37f4 pcm_utils: moved channel conversion functions to pcm_channels.c
Separate code from pcm_utils.c to keep it small and simple.
2008-10-23 20:03:14 +02:00
Max Kellermann
af7cb932fb pcm_resample: implemented 24 bit resampling
Similar to pcm_resample_16(), implement pcm_resample_24().  The 24 bit
implementation is very similar, but it uses src_int_to_float_array()
instead of src_short_to_float_array() before sending data to
libsamplerate.
2008-10-23 20:02:51 +02:00
Max Kellermann
5bbcbfb7ce pcm_resample: moved code to pcm_resample_set()
A future patch will implement a 24 bit resampler.  To unify code, move
code which can be shared to a separate function.
2008-10-23 20:02:09 +02:00
Max Kellermann
1dcb946fb0 pcm_resample: eliminated "sample" local variables
Copy from source to destination buffer directly, don't use the
temporary variables "lsample" and "rsample".
2008-10-23 20:01:37 +02:00
Max Kellermann
124f79a2a6 pcm_resample: don't resample partial samples
Added assertions which ensure that there are no partial samples in the
source buffer.
2008-10-23 20:01:12 +02:00
Max Kellermann
b13d656f81 pcm_resample: don't hard-code sample size
Use sizeof(sample) instead of hard-coding "2".  Although we're in 16
bit right now, this will make code sharing easier when we support
other sample sizes.
2008-10-23 20:01:08 +02:00
Max Kellermann
6b1c54ef96 pcm_utils: moved code to pcm_resample.c
Separate the resampling code from the rest of pcm_utils.c.  Create two
sub-libraries: pcm_resample_libsamplerate.c and
pcm_resample_fallback.c.
2008-10-23 20:00:51 +02:00
Max Kellermann
098991f8e8 command: fix boolean value parser
Due to a logic error, no value was valid for the boolean value
parser.  Replace "||" with "&&".
2008-10-23 18:06:05 +02:00
Max Kellermann
2cc2420f8c mp3: send 24 bit PCM data
libmad produces samples of more than 24 bit.  Rounding that down to 16
bits using dithering makes those people lose quality who have a 24 bit
capable sound device.  Send 24 bit PCM data, and let the receiver
decide whether to apply 16 bit dithering.
2008-10-23 16:58:38 +02:00
Max Kellermann
bf5774edbd mp3: use sizeof(sample) instead of hard-coded "2"
We are going to convert the code to 24 bit; don't hard-code a sample
size of 2 bytes.
2008-10-23 16:58:14 +02:00
Max Kellermann
0078837a97 pcm_dither: added generic 24 to 16 bit dithering
Copied and adapted code from the mp3 decoder plugin.  This library now
replaces the old and low-quality function pcm_convert_24_to_16().
2008-10-23 16:58:07 +02:00
Max Kellermann
80603cf6f1 audio: allow 24 and 8 bit output
I added 24 bit support a while ago, but it wasn't possible to force 24
bit output.  Add 24 and 8 bit to the list of allowed sample sizes.
Although 8 bit audio isn't as widely used as 24 bit, there is no
reason to exclude it.
2008-10-23 16:57:58 +02:00
Max Kellermann
980f2ca56d output_buffer: don't split frames
Splitting a frame between two buffer chunks causes distortion in the
output.  MPD used to assume that the chunk size 1020 would never cause
splitted frames, but that isn't the case for 24 bit stereo (127.5
frames), and even less for files with even more channels.
2008-10-23 16:48:49 +02:00
Max Kellermann
4f807b3aaa stored_playlist: don't map files outside the database
Don't attempt to map paths which are already absolute with
map_song_fs(): check with song_in_database() instead of
song_is_file().
2008-10-23 09:54:42 +02:00
Max Kellermann
fdc9a4cc5a stored_playlist: emit idle event on delete
The "rm" command did not send notifications to idle clients.  Add it.
2008-10-23 09:54:39 +02:00
Max Kellermann
93598e28f4 stored_playlist: renamed and moved spl_delete() to stored_playlist.c
The function deletePlaylist() shouldn't be in playlist.c.
2008-10-23 09:54:32 +02:00
Max Kellermann
39f0c41fbf stored_playlist: spl_load() returns GPtrArray
Don't use our deprecated linked list library, use GLib's GPtrArray
instead.
2008-10-23 09:54:28 +02:00
Max Kellermann
e172874cc6 command: check over/underflows in check_int()
The "long" result of strtol() was implicitly casted down to a 32 bit
integer.  Add some range checking instead.
2008-10-23 09:54:10 +02:00
Max Kellermann
95ae1d9e9e command: added check_unsigned() / check_bool()
Many command arguments must not be negative; add a separate
parser/checker function for that.  For the same reason, add
check_bool().  This eliminates two strange special cases handlers from
check_int().
2008-10-23 09:53:35 +02:00
Max Kellermann
3958457256 stored_playlist: unsigned index arguments
Pass index arguments as unsigned integers.  They must not be negative,
and even if some caller accidently passes -1, it won't pass the bound
checks (since it's now 2**32-1).
2008-10-23 09:53:34 +02:00
Max Kellermann
bc938603f6 playlist: unsigned integers
There are some integers which have a "magic" -1 value which means
"undefined" or "nothing".  All others can be converted to unsigned,
since they must not contain a negative number.
2008-10-23 07:19:46 +02:00
Max Kellermann
890b067346 command: use the bool datatype instead of int
Instead of returning 0 for success and -1 for failure, return true or
false.  This seems more natural.
2008-10-22 21:41:54 +02:00
Max Kellermann
d4f3c09081 command: converted COMMAND_RETURN_* macros to enum
Also add names for "error" and "ok".  I don't like passing anonymous
integer codes around.

This is not yet complete: lots of functions (e.g. in playlist.c)
follow the same convention of -1/0, and these have to be adapted, too.
2008-10-22 21:41:49 +02:00
Max Kellermann
d11ee6580c command: replaced "goto" with "break"
http://xkcd.com/292/
2008-10-22 21:40:58 +02:00
Max Kellermann
51a6ee88f7 command: no CamelCase
Eliminate CamelCase in all public and static functions.
2008-10-22 21:40:44 +02:00
Max Kellermann
69c563b511 command: removed CommandHandlerFunction typedef
The typedef CommandHandlerFunction is only used once.  Move its type
into the command struct.
2008-10-22 21:40:36 +02:00
Max Kellermann
d0a9dcdcf5 ack: converted ACK_ERROR_* macros to enum 2008-10-22 21:40:32 +02:00
Max Kellermann
7aca4cd194 stored_playlist: send timestamps
Send last modification timestamps to the client.  This allows the
client to see when another client modifies a stored playlist.
2008-10-22 19:18:39 +02:00
Max Kellermann
9c983c442c command: added command "listplaylists"
"listplaylists" returns a list of all stored playlists.  This command
seems more elaborate than listing them below "lsinfo".
2008-10-22 19:16:56 +02:00
Max Kellermann
f8e586402d command: added print_spl_list()
The function print_spl_list() replaces the old function lsPlaylists()
from ls.c.
2008-10-22 19:16:35 +02:00
Max Kellermann
a65e20b50e stored_playlist: added spl_list()
spl_list() provides an interface for enumerating all stored playlists.
This separates the internal playlist logic from the protocol specific
function lsPlaylists().
2008-10-22 19:15:50 +02:00
Max Kellermann
3a164ef8e6 stored_playlist: spl_append_uri() returns enum playlist_result
The return value of spl_append_uri() was somewhat buggy: some branches
returned ACK_* values, and some an enum playlist_result.  Unify this.
2008-10-22 17:24:40 +02:00
Max Kellermann
d2606baa79 stored_playlist: de-CamelCase moved function
Rename addToStoredPlaylist() to spl_append_uri(), and remove the
clearStoredPlaylist() macro.
2008-10-22 17:23:58 +02:00
Max Kellermann
1da921f03c stored_playlist: moved functions from playlist.c
The two functions clearStoredPlaylist() and addToStoredPlaylist()
don't belong into playlist.c.  clearStoredPlaylist() was a wrapper for
spl_clear(), and is converted into a CPP macro for now.
2008-10-22 17:23:11 +02:00
Max Kellermann
ac853b6165 stored_playlist: no CamelCase
Renamed all public functions, prefix is "spl_".
2008-10-22 17:21:59 +02:00
Max Kellermann
a4def81313 renamed storedPlaylist.c to stored_playlist.c
No CamelCase in file names.
2008-10-22 17:21:57 +02:00
Max Kellermann
1c62e2cd62 command: added "commands" array instead of registering manually
The list of commands is known at compile time.  Instead of creating a
linked list on startup, we can just register all commands in a static
sorted array.
2008-10-22 10:08:14 +02:00
Max Kellermann
84d0f56eaf command: make command pointers constant
The command pointers which are passed around aren't being modified -
in fact, no command pointer must be modified once it has been added to
the commandList.
2008-10-22 09:59:01 +02:00
Max Kellermann
4b4f7df933 command: renamed CommandEntry to struct command
No CamelCase and no struct typedefs.
2008-10-22 09:58:13 +02:00
Max Kellermann
e6d90d4e83 pcm_utils: added pcm_convert_init()
Instead of manually calling memset(0) on the pcm_convert_state struct,
client code should use a library function from pcm_utils.c.  This way,
we can change the semantics of the struct easily.
2008-10-21 22:53:16 +02:00
Max Kellermann
ca6e613a7f pcm_utils: no CamelCase
Renamed all functions which were still in CamelCase.
2008-10-21 22:53:13 +02:00
Max Kellermann
fb416964d6 pcm_utils: renamed ConvState to struct pcm_convert_state
No CamelCase, and a struct instead of a typedef.
2008-10-21 21:59:43 +02:00
Max Kellermann
a7888c4998 ffmpeg: don't pass pointer as hexadecimal string
Casting a pointer to some sort of integer and formatting it into a
string isn't valid.  A pointer derived from this hex string won't work
reliably.  Since ffmpeg doesn't provide a nice API for passing our
pointer, we have to think of a different hack: ffmpeg passes the exact
URL pointer to mpdurl_open(), and we can make this string part of a
struct.  This reduces the problem to casting the string back to the
struct.

This is still a workaround, but this is "sort of portable", unless the
ffmpeg people start messing with the URL pointer (which would be valid
according to the API definition).
2008-10-21 18:12:56 +02:00
Max Kellermann
def97411f2 ffmpeg: detect which ffmpeg headers should be included
Since ffmpeg svn r12865, you have to include libavcodec/avcodec.h
instead of avcodec.h.  This cannot be checked at compile time, instead
we have to add a check to configure.ac.  Viliam's original ffmpeg
plugin was based on the newer ffmpeg library, while my Debian
installation had the older version.  My attempt to correct his include
statements wasn't correct after all.
2008-10-21 08:34:19 +02:00
Eric Wong
d52437d43f update: fix multiple deletes from *vec iterators
{song,dir}vec_for_each each failed to gracefully handle deleted
files when iterating through.  While we were thread-safe, we
were not safe within the calling thread.  If a callback we
passed caused sv->nr to shring, our index would still increment;
causing files to stay in the database.

A way to test this is to remove 10 or so contiguous songs from a
>10 song directory.
2008-10-21 01:35:11 +02:00
Eric Wong
9aeacdef56 dirvec: introduce locking for all iterators
Like the songvec nr_lock, only one lock is used for all
traversals since they're rarely changed.  This only
projects traversals, but not the individual structures
themselves.
2008-10-21 01:34:36 +02:00
Eric Wong
686a6df3a5 {dir,song}vec: these structs are const
We definitely don't modify them here.
2008-10-21 01:31:36 +02:00
Eric Wong
f2525e3efb dirvec: add dirvec_for_each iterator
This will make it easier to introduce locking
2008-10-21 01:30:30 +02:00
Max Kellermann
1d385190a0 path: removed pathcpy_trunc()
There was only one user of pathcpy_trunc(), which can be eliminated.
2008-10-20 22:18:42 +02:00
Max Kellermann
49260e6db2 path: replaced parent_path() with g_path_get_dirname()
Again, GLib's version is more robust than ours.
2008-10-20 22:18:40 +02:00
Max Kellermann
ba96920a52 path: replaced mpd_basename() with g_path_get_basename()
GLib's g_path_get_basename() is much more reliable than
mpd_basename().  The latter could be tricked into an assertion
failure.
2008-10-20 22:18:12 +02:00
Max Kellermann
99e82a2ef2 signal_check.c: don't use leading underscores
Identifiers with two leading underscores are reserved for the C
compiler's internal use.  Don't use them in the source.
2008-10-20 22:18:03 +02:00
Max Kellermann
57f5e8731d mapper: don't return database path with leading slash
Due to an off-by-one bug in map_fs_to_utf8(), the function returned
database paths with a leading slash.
2008-10-19 00:05:39 +02:00
Andrzej Rybczak
52123c1de8 listen: fix "struct ucred" check
The macro name is HAVE_STRUCT_UCRED, not HAVE_UCRED.
2008-10-18 18:21:49 +02:00
Max Kellermann
98f7177f4a input_stream: don't declare method typedefs
The typedefs aren't using by anybody but struct input_stream.  Remove
them and declare the method type within struct input_stream.
2008-10-18 08:17:55 +02:00
Max Kellermann
1dfe92057e ffmpeg: make internal functions static
The mpdurl_* code is internal, don't expose them.  Also don't
initialize struct members with NULL.
2008-10-18 08:08:13 +02:00
Max Kellermann
02a2a407c1 client: converted permissions to unsigned
client->permission is a bit set, and should be unsigned.
2008-10-17 23:53:28 +02:00
Max Kellermann
f8d5b74071 client: eliminate variable "left" in client_write()
Reduce two temporary variables to only one.
2008-10-17 23:53:16 +02:00
Max Kellermann
bdbccc633d client: fixed send buffer
There is no sense in using the kernel's send buffer size (SO_SNDBUF)
for MPD's send buffer.  Convert it into a static buffer of 4 kB.
2008-10-17 23:52:47 +02:00
Max Kellermann
48c11c52ac client: removed CLIENT_MAX_BUFFER_LENGTH
Use a literal in the struct declaration, and sizeof(client->buffer)
everywhere else.  Also shrink the buffer from 40 kB to 4 kB.  The
buffer must only be large enough to hold one line of input, and 4 kB
is still more than enough.
2008-10-17 23:52:40 +02:00
Max Kellermann
3689d5e4ed client: added assertions on the buffer pointers
The buffer pointers must not exceed the buffer size.
2008-10-17 23:29:41 +02:00
Max Kellermann
d691577a96 client: read() return value is ssize_t
Use ssize_t instead of int.
2008-10-17 23:26:40 +02:00
Max Kellermann
79459d08d9 client: handle partial lines correctly
Commit 6eb62e47 didn't obey partial lines correctly: when a line
wasn't finished in one read, the first part was ignored when the rest
arrived.
2008-10-17 23:23:54 +02:00
Viliam Mateicka
11ad997141 ffmpeg: new decoder plugin
[mk: fixed indent, changed copyright statement, added autoconf test,
fixed includes paths, fixed 2 gcc warnings, don't close input stream
twice]
2008-10-17 22:27:33 +02:00
Max Kellermann
4ee8da2e69 Makefile.am: don't compile disabled decoder plugins
Don't compile the sources of disabled decoder plugins at all, and
don't attempt to register these.
2008-10-17 21:57:09 +02:00
Max Kellermann
25b5d90e44 Makefile.am: don't compile disabled sources
If a feature is disabled, don't compile the source file at all,
disable it completely in Makefile.am instead.
2008-10-17 21:13:23 +02:00
Max Kellermann
4984639b72 input_stream: removed nmemb argument
The nmemb argument isn't actually useful, and one of nmemb and size
was always passed as 1.  Remove it.
2008-10-17 17:53:59 +02:00
Max Kellermann
b73ecbb073 input: declare struct input_stream
Provide a struct type which can be forward-declared.  The typedef
InputStream is deprecated now.
2008-10-17 17:53:48 +02:00
Max Kellermann
bae98f777b decoder: notify player after entering decodeStart()
Wake up the player as soon as the decoder thread has entered its loop.
This fixes a dead lock when the input is blocking.
2008-10-17 17:53:44 +02:00
Max Kellermann
7ca19736c9 command: expect "file:///" url for local files
When adding a local file, clients have to use the "file" URI schema
described in RFC 1738 3.10.  By adding this schema to "urlhandlers", a
client can detect whether this feature is available.
2008-10-17 17:53:43 +02:00
Max Kellermann
f548216ead listen: fixed unused variable warning without HAVE_UCRED
The local variable "passcred" was only used by ucred code.
2008-10-17 17:40:28 +02:00
Max Kellermann
9b5ce27c3b configure.ac: check if "struct ucred" is available
By default, glibc 2.8 hides struct ucred behind the _GNU_SOURCE
macro.  I don't want to enable that globally, because it may encourage
the use of non-portable functions.  Test if "struct ucred" is
available, and enable _GNU_SOURCE if required.

For details about that issue, see glib's bug database:

 http://sources.redhat.com/bugzilla/show_bug.cgi?id=6545
2008-10-16 14:59:26 +02:00
Max Kellermann
b53365949a configure.ac: find more libraries with pkg-config
Detect the following libraries with pkg-config: libshout, libid3tag,
libmad.
2008-10-16 08:33:29 +02:00
Max Kellermann
beec15ddaa command: special case for "add /"
The undocumented command "add /" adds the full music database to the
playlist.  Don't interpret this special path as a local file path.
2008-10-16 07:40:34 +02:00
Max Kellermann
f9222fdabe playlist: also allow world-readable local files
Allow a local user to not only add his own files, but also all
world-readable files (mode 0444).
2008-10-15 23:10:05 +02:00
Max Kellermann
f1ab4d2c1b song: check file type in song_file_update()
Don't load non-regular files.
2008-10-15 22:43:24 +02:00
Max Kellermann
8c0060fae4 playlist: added support for adding songs not in the music database
Clients which have authenticated via unix socket may add local files
to the MPD playlist, provided that they own the file.
2008-10-15 22:35:13 +02:00
Max Kellermann
0b44cad2ce command: print error message on "addid" failure
Returning the playlist_result value from a command handler does not
make sense.  Call print_playlist_result() there, and forward its
return value.
2008-10-15 22:35:04 +02:00
Max Kellermann
961a349f15 playlist: moved code to song_by_url()
Replace some complicated checks from addToPlaylist() to the simpler
function song_by_url().
2008-10-15 22:35:00 +02:00
Max Kellermann
6d3488c8b3 song: added song_in_database()
Some functions assume that a song is not in the database when it is a
remote song.  Based on that, they decide whether they are responsible
for freeing the song struct.  Add a special function which checks
whether a song is in the database (currently equal to song_is_file()).
2008-10-15 22:34:47 +02:00
Max Kellermann
4a7ad5b618 listen, client: enable SO_PASSCRED, get client's uid
Enable authentication over unix sockets.  Store the client's uid in
the client struct.
2008-10-15 22:34:21 +02:00
Max Kellermann
fa56ff3d52 update: don't skip hidden files
Skip only the special directory entries "." and "..", don't skip all
other "hidden" files.
2008-10-15 20:51:01 +02:00
Max Kellermann
92513c3309 shout: check for vorbisenc library
The switch from ogg.m4 to pkg-config intentionally disabled
libvorbisenc.  Enable it when shout_ogg is used.
2008-10-15 20:40:04 +02:00
Enrico Weigelt
30cd345581 fixing several imports to work via pkg-config
This patch fixes several imports to use pkg-config instead of certain
esoteric tests.
2008-10-15 20:39:46 +02:00
Max Kellermann
047043d2a8 locate: use g_utf8_casefold() instead of string_toupper()
string_toupper() and strDupToUpper() were not able to deal with
character sets other than US-ASCII.  Use GLib's g_utf8_casefold()
for strings.
2008-10-15 19:36:37 +02:00
Max Kellermann
7366191f0d mapper: moved musicDir initialization from path.c
Moved the musicDir variable and its initialization code from path.c to
mapper.c.
2008-10-15 19:36:33 +02:00
Max Kellermann
76779f0fbe path: allow starting MPD with non-existing music directory
When the music directory is not mounted yet, let MPD start anyway.
2008-10-15 19:36:31 +02:00
Max Kellermann
8746a58ab9 path, tag_id3: use g_convert() instead of charConv.c
GLib provides an easier API for character set conversion than iconv().
Use g_convert() / g_convert_with_fallback() for all character
conversions.  We should optimize the path.h API later to return a
newly allocated buffer, so we can just pass GLib's return value.
2008-10-15 19:36:30 +02:00
Max Kellermann
e89599eaad use GLib
GLib is a nice and portable utility library.  We are going to use it
from now on, and eliminate a lot of duplicated code from MPD.  Why
invent the wheel again and again?
2008-10-15 19:35:04 +02:00
Max Kellermann
2a47e90cf5 tag_id3: fix indentation
Indentation was broken in tag_id3.c: it used 4 spaces instead of tabs.
2008-10-15 19:29:46 +02:00
Max Kellermann
cf7ed8c5df idle: client command "noidle" aborts idle 2008-10-15 18:21:57 +02:00
Max Kellermann
6eb62e4761 client: optimized client_input_received()
Use memchr() instead of manually traversing the input buffer.  Update
the client's properties after all commands have been processed.  Check
for buffer overflow once.
2008-10-15 18:21:45 +02:00
Max Kellermann
62ee702877 listen: pass protocol family to establishListen()
The caller already knows the protocol family, and we can eliminate the
complicated switch statement in establishListen() if we just pass this
information.  This seems more robust.
2008-10-15 07:30:24 +02:00
Max Kellermann
ba594cfec0 listen: use getaddrinfo() instead of gethostbyname()
getaddrinfo() is more robust and has proper IPv6 support.  The new
code tries to bind to all IP addresses returned by getaddrinfo().
2008-10-15 07:20:53 +02:00
Max Kellermann
a3e3d2c950 command: added command "idle"
"idle" waits until something noteworthy happens on the server,
e.g. song change, playlist modified, database updated.  This allows
clients to keep up to date without polling.
2008-10-14 22:38:14 +02:00
Max Kellermann
30c86d8ae6 alsa: added #ifdefs around SND_PCM_NO_AUTO_xxx
These macros are not available in older libasound versions (1.0.13
fails, 1.0.16 is ok).  Ignore the configuration if the constants are
not defined.
2008-10-14 22:37:27 +02:00
Max Kellermann
da1c0cd6d7 playlist: don't use uninitialized local variable (typo)
Instead of the uninitialized local variable "s", I should have used
"uri".
2008-10-14 17:23:24 +02:00
Max Kellermann
c4a43f8a9d oss: use unsigned integer for ioctl constants
The OSS constants overflow a signed integer, use unsigned instead.
2008-10-14 17:21:57 +02:00
Max Kellermann
f01a08d5c2 oss: convert several macros to enum
C enums are nicer than CPP macros.
2008-10-14 17:21:53 +02:00
Max Kellermann
86782faa18 alsa: optionally disable resampling and others
Added mpd.conf options for disabling automatic resamling, sample
format and channel conversion.  This way, users may choose to override
ALSA's automatic resampling, and use libsamplerate instead.
2008-10-14 17:21:49 +02:00
Max Kellermann
ba892cbcb0 changed package name to "mpd-mk", updated version number
This git branch has become a real MPD fork now.  Time to change the
package name to the code name "mpd-mk".  Set the version number to
"0.14~git" to mark this as a non-released version.
2008-10-14 17:21:27 +02:00
Max Kellermann
197caee151 update: don't follow relative symlinks
Don't follow relative symlinks which point into the music directory.
This allows you to organize music with symbolic links, without MPD
managing separate copies of each song.
2008-10-14 11:10:54 +02:00
Max Kellermann
f521c12d20 ls: removed myStat(), isFile(), isDir()
The mapper code has replaced these functions.
2008-10-14 11:10:51 +02:00
Max Kellermann
5b71d5f6f7 mapper: new song-to-filesystem mapper library
The mapper library maps directory and song objects to file system
paths.  With this central library, the code mixture in path.c should
be cleaned up, and we will be able to add neat features like aliasing.
2008-10-14 11:10:49 +02:00
Max Kellermann
a52a9fc1fc playlist: moved code to playlist_save.c
playlist_print_song() and playlist_print_uri() handle charset
conversion and (optional) music directory prefixing.
2008-10-14 11:10:47 +02:00
Max Kellermann
308bc230b2 song: pass const song pointer to song_get_url()
song_get_url() doesn't modify the song object.
2008-10-14 11:10:44 +02:00
Eric Wong
06c8a9ed0b {dir,song}vec: fix off-by-one errors in {dir,song}vec_delete
Found by Valgrind while looking for another bug...

Hmm.. I should really just make this code generic since
they're duplicated...
2008-10-14 11:10:00 +02:00
Max Kellermann
f71ac4d479 song: stat file in song_file_update(), don't use isMusic()
isMusic() used to be a very inefficient function: with every
invocation, it did another stat() on the specified file.  There is
only one caller, do the stat() there manually and use hasMusicSuffix()
instead of isMusic().
2008-10-13 16:56:00 +02:00
Max Kellermann
94a5a5a985 update: always look up parent directory in updatePath()
By always creating the parent directory, we can use delete_name_in()
without further lookups.  The parents which may non exist will be
pruned later.  An update request for a non-existing or empty directory
should be quite unusual, so this doesn't add any measurable overhead.
2008-10-13 16:55:55 +02:00
Max Kellermann
a52343732b update: pass base file name to updateInDirectory()
In order to optimize buffer usage, pass only the base file name to
updateInDirectory().  This way, updateInDirectory() may choose when to
allocate a larger buffer for the full path.
2008-10-13 16:55:54 +02:00
Max Kellermann
270a6ebd69 update: moved code to make_subdir() 2008-10-13 16:46:51 +02:00
Max Kellermann
3e9ed15e76 update: added delete_name_in()
delete_name_in() is similar to delete_path(), but it does not need to
look up the parent directory.
2008-10-13 16:46:32 +02:00
Max Kellermann
69617438a9 dirvec: dirvec_find() compares basename
It is invalid to pass a path with the wrong dirname to dirvec_find().
To be able to find a subdirectory only by its basename, compare only
the basename of both paths.
2008-10-13 16:33:04 +02:00
Max Kellermann
3b6ff84393 directory: added directory_get_name()
directory_get_name() returns the base name of the directory.
2008-10-13 16:32:39 +02:00
Max Kellermann
bc85e92a72 playlist: don't use isPlaylist() in deletePlaylist()
The only caller of deletePlaylist() appends PLAYLIST_FILE_SUFFIX, so
we can be sure it's already there.  We don't need to stat the file,
since unlink() does all the checking.
2008-10-13 16:30:44 +02:00
Max Kellermann
07c9b62764 audio: don't clear input_audio_format on openAudioDevice(NULL)
Commit 80a2c937 broke resume after pause: it cleared the
input_audio_format when it attempted to simplify a complicated
expression.  Don't clear it, just assign input_audio_format if a new
format was specified.
2008-10-13 14:31:18 +02:00
Max Kellermann
5ea2e198f9 directory: pass const pointers to inline functions
The inline functions directory_is_empty() and directory_get_path()
don't modify the object - pass constant object pointers to them.
2008-10-13 09:56:57 +02:00
Eric Wong
313405edb6 songvec: avoid holding nr_lock during free(3)
We only need to lock sv->nr changes to prevent traversals ( why
it's called "nr_lock").  free(3) is a "slow" function on my
system; so we can avoid unnecessarily holding a lock long for
longer than needed.
2008-10-13 09:55:07 +02:00
Eric Wong
3035a3303d update: allow music_root updates to be queued
Previously only updates with subdirectories being
specified could be queued.  No harm in queueing
full updates.
2008-10-13 09:55:03 +02:00
Eric Wong
8d907fb9fa directory: use mpd_sizeof_str_flex_array for path, too
This way we avoid unnecessary heap allocations.
2008-10-13 09:55:00 +02:00
Eric Wong
8867bd554c tag_item: avoid wasting space when struct is unpackable
Not all compilers support struct packing, and those that don't
shouldn't be punished for it.
2008-10-13 09:40:14 +02:00
Eric Wong
c641aabe33 song: song_get_url: fix "/" prefix for songs in music_root 2008-10-13 09:39:02 +02:00
Aaron McEwan
2139d8bba8 shout: make the protocol configurable
Added configuration parameter "protocol" which lets the user choose
from 3 shout protocols.  This adds support for real shoutcast servers.
2008-10-12 12:14:51 +02:00
Max Kellermann
ff69f12259 shout: use strcmp() instead of strncasecmp()
Case insensitivity isn't helpful, and comparing only the first 3 bytes
of a configured value may encourage users to supply wrong or
misleading values.
2008-10-12 12:13:27 +02:00
Max Kellermann
ffed2fdca7 alsa: fall back to 16 bit output
If the sample format isn't supported by the device (i.e. 24 bit on
low-end sound chips), fall back to 16 bit output.  There is code in
pcm_utils.c which converts PCM data to 16 bit.
2008-10-12 12:02:55 +02:00
Max Kellermann
9b0693d8ef pcm_utils: support any number of channels in pcm_sizeOfConvBuffer()
When calculating the conversion buffer size, don't hard-code the
formulas for only mono<->stereo.
2008-10-12 12:02:54 +02:00
Max Kellermann
c0ecce5498 pcm_utils: support converting N channels to stereo
Convert any number of channels to stereo.  In fact, this isn't really
stereo, it's rater mono blown up to stereo.  This patch should only
make it possible to play 5.1 files at all; "real" conversion to stereo
should be implemented, but for now, this is better than nothing.
2008-10-12 12:02:52 +02:00
Max Kellermann
52949453df pcm_utils: pass output channel count to pcm_convertChannels()
In order to be able to deal with non-trivial conversions,
pcm_convertChannels() needs to know both the input and the output
channel count.  Simplify buffer allocation in that function.
2008-10-12 11:51:19 +02:00
Max Kellermann
a7924d141d pcm_utils: moved code from pcm_convertChannels() to separate functions
Moved code from pcm_convertChannels() to pcm_convert_channels_1_to_2()
and pcm_convert_channels_2_to_1().  Improved the quality of
pcm_convert_channels_2_to_1() by calculating the arithmetic mean value
of both samples.
2008-10-12 11:47:42 +02:00
Max Kellermann
1a74d7be41 alsa: moved code to alsa_configure()
Move code which loads configuration to alsa_configure().  This removes
one indent level.
2008-10-12 11:47:33 +02:00
Max Kellermann
0d3a6ff669 pcm_utils: pass int16_t* where appropriate
Pass int16_t pointers instead of char pointers to functions which can
deal with 16 bit audio only.
2008-10-12 11:28:37 +02:00
Max Kellermann
08210af23a player: replaced buffered_before_play with buffering flag
buffered_before_play was copied to struct player because it was used
to disable buffering when seeking.  Instead of mainaining a copy of
this number, move just the flag to the player struct.
2008-10-12 01:21:35 +02:00
Max Kellermann
80a2c937c4 audio: renamed the audio_format variables
Renamed audio_configFormat to configured_audio_format.  Renamed
audio_buffer.format to input_audio_format.  Simplified its
initialization in openAudioDevice().
2008-10-12 01:00:00 +02:00
Max Kellermann
336b193097 audio: removed enum ad_state
All what's left from ad_state is a simple boolean flag (ENABLE /
DISABLE).  Convert it to a C99 bool.
2008-10-12 00:48:59 +02:00
Max Kellermann
c297c8555f audio: removed audio_buffer.buffer
audio.c maintained one of MPD's many layers of audio buffers.  It was
without any benefit, since playAudio() can simply send the source
buffer directly to the audio output plugin.
2008-10-12 00:42:33 +02:00
Max Kellermann
ea25688e46 output_buffer: converted ob_is_empty() to inline
The function ob_is_empty() is called very often.  It's worth it to
convert it to an inline function.
2008-10-12 00:42:22 +02:00
Max Kellermann
35a939e3e7 player: added commands QUEUE and CANCEL
QUEUE adds a new song to the player's queue.  CANCEL clears the queue.
These two commands replace the old and complex queueState and
queueLockState code.
2008-10-12 00:07:54 +02:00
Max Kellermann
35a16b9923 playlist: call clearPlayerQueue() only if song is queued
Simplify and merge several if clauses before the clearPlayerQueue()
invocation.  Call clearPlayerQueue() only if a song is actually
queued; add an assertion for that in clearPlayerQueue().
2008-10-12 00:03:27 +02:00
Max Kellermann
9d51bd392b player: added struct player
The player struct holds the local variables which used to be passed to
all those helper functions in player_thread.c.
2008-10-12 00:02:23 +02:00
Max Kellermann
2fcbabf4d1 player: removed set_current_song()
set_current_song() is an internal function and consists of only one
assignment.  Eliminate it.
2008-10-11 12:52:57 +02:00
Max Kellermann
42409a35e2 player: removed player_control.fileTime
This variable is superfluous, it is only used to copy its value to
player_control.totalTime.  Since the original source of this value
(song->tag->time) will still be available at this point, we can safely
remove fileTime.
2008-10-11 12:52:51 +02:00
Max Kellermann
dd7711d86c alsa: don't override libasound's buffer_time and period_time
ALSA does a good job measuring its buffer_time and period_time.  Don't
override its defaults, unless the user demands it.
2008-10-11 12:52:48 +02:00
Max Kellermann
bcc443a8aa alsa: re-enable blocking mode
Revert e4f5d6bd "re-enable-nonblocking, but sleep if busy".
Non-blocking mode with manual sleeping doesn't help at all (by the
way, the patch should have used snd_pcm_wait() instead of
my_usleep()).  ALSA knows much more about the hardware quirks, so we
just let it do the job.
2008-10-11 12:47:20 +02:00
Max Kellermann
215d8aa8f6 oss: fix opening default OSS device
Leftover from the output API changes: oss_open_default() was changed
to return a void*, but it still returned "0" to report success.
Report the OssData pointer instead.
2008-10-11 12:40:48 +02:00
Max Kellermann
17d9c1708b player: don't wake up decoder after every frame
The decoder was woken up after each chunk which had been played.  That
caused a lot of superfluous context switches.  Wake up the decoder
only when a certain amount of the buffer has been consumed.  This
formula is somewhat arbitrary, and has to be proven experimentally.
2008-10-10 16:47:57 +02:00
Max Kellermann
f41fe1e0b5 mp3: dither an arbitrary number of channels
The mp3 plugin did not use the MAD_NCHANNELS() value correctly: when a
stream was not stereo, it was assumed to be mono, although the correct
number was passed to MPD.  libmad doesn't support more than 2
channels, but this change allows gcc to optimize its inlining
strategy.
2008-10-10 16:40:48 +02:00
Max Kellermann
bac136608d mp3: hard-code dithering to 16 bits
The dithering function audio_linear_dither() worked for signed 16 bits
only anyway, having a variable "bits" just disables important gcc
optimizations.
2008-10-10 16:34:52 +02:00
Max Kellermann
5de7521900 player: added player_get_audio_format()
player_get_audio_format() replaces getPlayerSampleRate(),
getPlayerBits(), getPlayerChannels().
2008-10-10 14:51:22 +02:00
Max Kellermann
0b4dfae22e player: added player_control.audio_format
This replaces the attributes bits, channels, sampleRate.
2008-10-10 14:47:58 +02:00
Max Kellermann
8c33b64847 mvp: unsinged integers
Fix some gcc warnings by using unsigned where appropriate.  Declare
numfrequencies as "const", and replaced the magic number 12 with a
sizeof.
2008-10-10 14:47:58 +02:00
Max Kellermann
cec9264d24 mvp: adapt to the new output device API 2008-10-10 14:47:56 +02:00
Max Kellermann
7d9bedc3aa mvp: missing includes
Again, a plugin which was disabled in my test environment and suffered
from compilation errors.
2008-10-10 14:47:54 +02:00
Max Kellermann
8fc6b93afc oss: added OssData.audio_format
This replaces the separate properties channels, sampleRate, bits.
2008-10-10 14:42:30 +02:00
Max Kellermann
96155a3376 audio_format: added audio_format_frame_size()
A frame contains one sample per channel, thus it is sample_size *
channels.  This patch includes some cleanup for various locations
where the sample size for 24 bit audio was still 3 bytes (instead of
4).
2008-10-10 14:41:37 +02:00
Max Kellermann
de2cb3f375 audio_format: renamed sampleRate to sample_rate
The last bit of CamelCase in audio_format.h.  Additionally, rename a
bunch of local variables.
2008-10-10 14:40:54 +02:00
Max Kellermann
6101dc6c76 audio_format: unsigned integers
"bits" and "channels" cannot be negative.
2008-10-10 14:03:33 +02:00
Max Kellermann
817a033f55 update: replaced update_return with global "modified" flag
There is only once update thread at a time.  Make the "modified" flag
global and remove the return values of most functions.  Propagating an
error is only useful for updateDirectory(), since updateInDirectory()
will delete failed subdirectories.
2008-10-09 19:41:58 +02:00
Max Kellermann
b8115f2a5f update: make the variable "progress" static 2008-10-09 19:31:31 +02:00
Max Kellermann
da7166bdd2 update: don't print debug message when song was not modified
When a song file was not modified, MPD printed the debug message "not
a directory or music", because the first "if" branch did not return.
2008-10-09 19:20:59 +02:00
Max Kellermann
478d0ba7bb update: fix memory leak in directory_update_init()
When the update queue is full, directory_update_init() did not free
the path argument.
2008-10-09 19:20:54 +02:00
Max Kellermann
4beba26c61 update: make the job id unsigned
Since the return value cannot be -1 anymore, we can make it unsigned.
2008-10-09 19:20:05 +02:00
Max Kellermann
f1022bcc12 update: job ID must be positive
The documentation for directory_update_init() was incorrect: a job ID
must be positive, not non-negative.  If the update queue is full and
no job was created, it makes more sense to return 0 instead of -1,
because it is more consistent with the return value of isUpdatingDB().
2008-10-09 19:17:44 +02:00
Max Kellermann
79a28e5c72 update: check progress!=IDLE in reap_update_task()
When the update task is idle, there is no need to check for deleted
songs.  Return early from reap_update_task().
2008-10-09 19:17:38 +02:00
Max Kellermann
69e34f11f5 update: fixed stack corruption due to pthread_join() call
pthread_join() expects a "pointer to a pointer" parameter, but it got
a "pointer to an enum".  On AMD64, an enum is smaller than a pointer,
leading to a buffer overflow.
2008-10-09 19:17:33 +02:00
Max Kellermann
b4f1b20fd9 updated: always call removeDeletedFromDirectory()
Removed the local variable "was_empty": don't remember if the
directory is new.  Always call removeDeletedFromDirectory().
2008-10-09 19:17:26 +02:00
Max Kellermann
84b52265a6 update: eliminated addSubDirectoryToDirectory()
In updateInDirectory(), add new directories immediately and
delete them when they turn out to be empty.  This simplifies the code
and allows us to eliminate addSubDirectoryToDirectory().
2008-10-09 19:17:25 +02:00
Max Kellermann
9604f88fe7 update: make the "song" variable more local 2008-10-09 19:16:21 +02:00
Max Kellermann
78899051c0 update: do the recursive directory check only once
The recursive checks were performed in several functions, and
sometimes a directory was checked twice.
2008-10-09 19:15:56 +02:00
Max Kellermann
a9799218ab update: copy stat to new directory
When reading a new directory, copy the stat data (which we have
anyway) to the directory struct.  This may save a stat() in the
future.
2008-10-09 19:14:04 +02:00
Max Kellermann
9935ef4034 update: avoid duplicate stat() calls
Pass a pointer to the stat struct to more functions.
2008-10-09 19:13:03 +02:00
Max Kellermann
953f186c8a update: rewrote updatePath() using updateInDirectory()
updatePath() duplicated a lot of code from the more generic
updateInDirectory().  Eliminate most of updatePath() and call
updateInDirectory().
2008-10-09 19:13:02 +02:00
Max Kellermann
7dd099a60f update: don't export updateDirectory()
If the user requests database update during startup, call
directory_update_init().  This should be changed to fully asynchronous
update later.

For this to work, main_notify has to be initialized before db_init().
2008-10-09 19:11:54 +02:00
Max Kellermann
0677116da0 update: pass const pointer to addSubDirectoryToDirectory()
The stat struct isn't going to be modified, make it const.
2008-10-09 19:11:51 +02:00
Max Kellermann
08c1322089 update: never pass root path to updatePath()
update_task() already checks if it has got a root path.  Extend this
check and in turn remove a check in the inner function updatePath().
2008-10-09 19:11:49 +02:00
Max Kellermann
6b9ffcffe2 database: renamed get_get_song() to db_get_song()
Search'n'replace typo..
2008-10-09 16:26:09 +02:00
Max Kellermann
4409c34a8c update: don't sanitize the path again
directory_update_init() has to be called with a path that is already
sanitized.  Don't call sanitizePathDup() again in updatePath().
2008-10-09 16:22:56 +02:00
Max Kellermann
a79bd723e2 update: merged addDirectoryPathToDB() into addParentPathToDB()
The algorithm in addDirectoryPathToDB() can be simplified further if
it is combined with the function addParentPathToDB().  Since there is
no other caller of addDirectoryPathToDB(), we can do that.  This saves
another large stack buffer.
2008-10-09 15:48:39 +02:00
Max Kellermann
4990f04ac0 update: make addDirectoryPathToDB() non-recursive
This recursive function is very dangerous because it allocates a large
buffer on the stack in every iteration.  That may be misused to
generate a stack overflow.
2008-10-09 15:48:07 +02:00
Max Kellermann
8536a97920 update: delete directory after failed update
When a directory cannot be updated, there must be something wrong with
it, and the database contains stale data.  Remove it.
2008-10-09 15:47:59 +02:00
Max Kellermann
0daba6bd43 update: moved code to directory_make_child_checked()
The branching looks a bit complicated in addDirectoryPathToDB() -
improve its readability by moving code to a simplified separate
function.
2008-10-09 15:47:22 +02:00
Max Kellermann
2ae94fec6d update: clear root after error
When the root directory fails to update, its contents are invalid.
Clear it then.
2008-10-09 15:42:30 +02:00
Max Kellermann
2bb7bcc7b6 update: locked delete after update error
When a directory failed to update, it was removed from the database,
without freeing all children and songs (memory leak), and without
locking (race condition).  Introduce the functions clear_directory()
and delete_directory(), which do both.
2008-10-09 15:41:02 +02:00
Max Kellermann
96c681e2db dirvec: added dirvec_clear() 2008-10-09 15:37:41 +02:00
Max Kellermann
476578d2a9 update: removed addToDirectory()
Use updateInDirectory() instead of addToDirectory().  Eliminate a
duplicate stat() in updateInDirectory() by calling song_file_update()
directly.
2008-10-09 15:37:21 +02:00
Max Kellermann
60d122e850 directory: don't query database during load
Don't use db_get_directory() and traverse the full path with every
directory being loaded.  Just see if the current parent contains the
entry.  Everything else would be invalid anyway..
2008-10-09 15:37:18 +02:00
Max Kellermann
702739b879 directory: check the absolute path of a subdirectory while loading
A manipulated database could trigger an assertion failure, because the
parent didn't match.  Do a proper check if the new directory is within
the parent's.  This uses FATAL() to bail out, so MPD still dies, but
it doesn't crash.
2008-10-09 15:35:34 +02:00
Max Kellermann
cbc0764613 directory: added inline wrappers for accessing children
Some tiny utilities... wrappers like these may become helpful when we
introduce locking.
2008-10-09 15:34:07 +02:00
Max Kellermann
a5480108f8 dirvec: constant pointers in dirvec_find()
dirvec_find() does not modify the object, thus it should get a const
pointer.
2008-10-09 15:24:34 +02:00
Max Kellermann
68f716a28b directory: moved dirvec struct declaration to dirvec.h
No idea why it was created in directory.h, but it should be in
dirvec.h.
2008-10-09 15:24:05 +02:00
Max Kellermann
a0c044df11 diretory: moved code to directory_save.c, directory_print.c
Remove clutter from directory.c.  Everything which saves or loads
to/from the hard disk goes to directory_save.c, and code which sends
directory information to the client is moved into directory_print.c.
2008-10-09 15:23:37 +02:00
Max Kellermann
cb12eb8e23 database: removed local variable bufferSize
Use sizeof(buffer) instead.
2008-10-09 15:21:23 +02:00
Max Kellermann
5dc4c325aa database: simplify db_load()
Removed a superfluous closure.
2008-10-09 15:21:18 +02:00
Max Kellermann
5583b6c5e1 shout: removed DISABLED_SHOUT_ENCODER_PLUGIN
Having an array with disabled entries sucks.  Removed that
DISABLED_SHOUT_ENCODER_PLUGIN macro, and fill the plugin list only
with plugins which are actually enabled.  This should be done for all
plugin types.
2008-10-09 15:18:21 +02:00
Max Kellermann
671b455133 pcm: fix const flac in pcm_convertSampleRate()
In the libsamplerate fallback code, a "const" attribute was missing.
2008-10-09 15:18:18 +02:00
Max Kellermann
40f59cacda pcm: fixed software volume, broken by unsigned integer
"volume" was passed as an unsigned integer, which is correct.  It's
just that when it was multiplied with the sample value, the whole
operation was changed to unsigned, breaking the algorithm (and Qball's
ears).  Internally change "volume" to signed.
2008-10-09 15:18:09 +02:00
Qball Cow
ecc3c39e2f Fix error code for "Playlist already exists"
With commit 6dcd7fea (if I am not mistaken) the error returned when
you try to save to an existing playlist is wrong.  Instead of
MPD_ACK_ERROR_EXIST, MPD_ACK_ERROR_NO_EXIST is returned.  This is
obviously wrong and breaks gmpc.
2008-10-09 11:51:22 +02:00
Max Kellermann
22645abc10 directory: fix update in root directory
Commit 0bfe7802 broke update for new files in the root directory,
because music_root->path was an empty string and not NULL.  There were
some NULL tests missing.  Change them to !isRootDirectory(path)
instead of path!=NULL.
2008-10-08 11:55:52 +02:00
Max Kellermann
e8413541f4 update: fix deadlock in delete_song()
Due to a merge error, reap_update_task() called cond_signal_async()
with a locked mutex.  That always fails.  Use cond_signal_sync()
instead.
2008-10-08 11:36:38 +02:00
Max Kellermann
81220ca206 directory: include sys/types.h
ino_t and dev_t are declared in sys/types.h, not sys/stat.h.
2008-10-08 11:25:33 +02:00
Max Kellermann
0bfe7802d2 directory: path must not be NULL
For the root directory, let's set path to an empty string.  This saves
a few checks.
2008-10-08 11:08:16 +02:00
Max Kellermann
3b6efa99da directory: directory_get_path(NULL) is not allowed
Also convert directory_get_path() to an inline function, which returns
a constant string.
2008-10-08 11:08:04 +02:00
Max Kellermann
68977af6e0 directory: eliminate CamelCase
CamelCase is ugly, rename the functions.
2008-10-08 11:07:58 +02:00
Max Kellermann
bb8a9533b1 database: renamed functions, "db_" prefix and no CamelCase
Yet another CamelCase removal patch.
2008-10-08 11:07:55 +02:00
Max Kellermann
7a023eb0b2 database: removed printDirectoryInfo()
The same can be achieved with directory_print(db_get_directory()).
2008-10-08 11:07:39 +02:00
Max Kellermann
8a50e8a266 directory: moved code to database.c
Taming the directory.c monster, part II: move the database management
stuff to database.  directory.c should only contain code which works
on directory objects.
2008-10-08 11:07:35 +02:00
Max Kellermann
ba5c9b0375 directory: converted isRootDirectory() to an inline function
The function isRootDirectory() is tiny and can be converted to an
inline function.  Don't allow name==NULL.
2008-10-08 11:06:44 +02:00
Max Kellermann
e1a4474ad4 song: don't allow calling song_get_url(NULL)
The runtime check suggests that the author has somehow thought
song_get_url(NULL) might be valid.  It should not be.  Replace it with
an assertion.
2008-10-08 11:06:37 +02:00
Max Kellermann
4ab6b59aaf song: use song_file_update() in song_file_load()
Eliminate duplicated code.
2008-10-08 11:06:27 +02:00
Max Kellermann
02e8c000d1 song: song_file_update() returns bool
Instead of returning 0 or -1, return true on success and false on
failure.  This seems more natural, and when the C library was
designed, there was no "bool" data type.
2008-10-08 11:06:26 +02:00
Max Kellermann
1f9b614850 song: don't check song_is_file() in song_file_update()
This function was never used on remote songs.  Replace the runtime
check with an assertion.
2008-10-08 11:05:38 +02:00
Max Kellermann
5e7b18f874 song: removed CamelCase
CamelCase is ugly...  rename all functions.
2008-10-08 11:05:34 +02:00
Max Kellermann
5e4be9e495 song: replaced all song constructors
Provide separate constructors for creating a remote song, a local
song, and one for loading data from a song file.  This way, we can add
more assertions.
2008-10-08 11:05:25 +02:00
Max Kellermann
4a510a2674 playlist: simplified setPlaylistRandomStatus()
Check the old status before assigning.  This saves a temporary
variable.
2008-10-08 11:05:02 +02:00
Max Kellermann
b084bc28ed use the "bool" data type instead of "int"
"bool" should be used in C99 programs for boolean values.
2008-10-08 11:03:39 +02:00
Max Kellermann
71351160b1 don't include os_compat.h
When there are standardized headers, use these instead of the bloated
os_compat.h.
2008-10-08 10:49:29 +02:00
Max Kellermann
ca68b1c80a CPP include cleanup
Include only headers which are really used.
2008-10-08 10:49:26 +02:00
Max Kellermann
b159832418 notify: removed the "Notify" typedef
Typedefs shouldn't be used, use the bare struct names instead.
2008-10-08 10:49:16 +02:00
Max Kellermann
d562ba5fbb song: converted typedef Song to struct song
Again, a data type which can be forward-declared.
2008-10-08 10:49:11 +02:00
Max Kellermann
25f67da58c directory: converted typedef Directory to struct directory
The struct can be forward-declared by other headers, which relaxes the
header dependencies.
2008-10-08 10:49:05 +02:00
Max Kellermann
3c1142cbcb update: merged exploreDirectory() into updateDirectory()
exploreDirectory() duplicates some code in updateDirectory().  Merge
both functions, and use directory_is_empty() to determine whether
update or explore mode should be used.
2008-10-08 10:48:55 +02:00
Max Kellermann
e79aacf1db directory: added directory_is_empty()
directory_is_empty() is a tiny inline function which determine if a
directory has any child objects (sub directories or songs).
2008-10-08 10:48:49 +02:00
Max Kellermann
7b9bed8398 directory: moved code to update.c
The source directory.c mixes several libraries: directory object
management, database management and database update, resulting in a
1000+ line monster.  Move the whole database update code to update.c.
2008-10-08 10:48:48 +02:00
Max Kellermann
4cfd356e12 dirvec: moved code to dirvec.c
Having all functions as static (non-inline) functions generates GCC
warnings, and duplicates binary code across several object files.
Most of dirvec's methods are too complex for becoming inline
functions.  Move them all to dirvec.c and publish the prototypes in
dirvec.h.
2008-10-08 06:55:10 +02:00
Max Kellermann
b42974eee1 notify: loop while no signal is pending
pthread_cond_wait() may wake up spuriously.  To prevent superfluous
state checks, loop until the "pending" flag becomes true.  Removed the
dangerous assertion.
2008-10-08 06:55:08 +02:00
Max Kellermann
46eda29d1c song: really make the song struct non-packed
Somehow I must have missed this in commit 22e40b61.
2008-10-07 22:15:06 +02:00
Eric Wong
81ce068085 directory: fix return value in removeDeletedFromDirectory
oops :x
2008-10-07 22:11:21 +02:00
Eric Wong
7d8c9cc7e3 directory: serialize song deletes from playlist during update
This makes the update code thread-safe and doesn't penalize
the playlist code by complicating it with complicated and
error-prone locks (and the associated overhead, not everybody
has a thread-implementation as good as NPTL).

The update task blocks during the delete; but the update task is
a slow task anyways so we can block w/o people caring too much.

This was also our only freeSong call site, so remove that
function.

Note that deleting entire directories is not fully thread-safe,
yet; as their traversals are not yet locked.
2008-10-07 22:11:16 +02:00
Eric Wong
2b965a5424 directory: use songvec_for_each for iterators
Get rid of songvec_write so we can enforce proper locking
2008-10-07 22:10:48 +02:00
Max Kellermann
c47f97e1dc song: use songvec_for_each() in songvec_print() / songvec_save()
songvec_for_each() has locking, use it instead of manually iterating
over the songvec items.
2008-10-07 22:10:42 +02:00
Max Kellermann
f0366cc8ca songvec: pass const pointers
Pass const songvec pointers to songvec_find() and songvec_for_each().
2008-10-07 22:09:55 +02:00
Eric Wong
8be6026336 dbUtils/directory: traverseAllIn forEachSong returns -1 on error
Being consistent with most UNIX functions...
2008-10-07 22:07:44 +02:00
Eric Wong
45334a23e1 songvec: lock traversals for thread-safe updates/reads
Only one lock is used for all songvec traversals since
they're rarely changed.  Also, minimize lock time and
release it before calling iterator functions since they
may block (updateSongInfo => stat/open/seek/read).

This lock only protects songvecs (and all of them) during
traversals; not the individual song structures themselves.
2008-10-07 22:07:34 +02:00
Eric Wong
bb04c6342e songvec: add songvec_for_each iterator
This is so we can more consistently deal with locking
needed for thread-safety in iterator functions.
2008-10-07 22:07:29 +02:00
Eric Wong
e19f6905d9 song: replace printSong* with song_print_*
This make argument order more consistent for iterators.
Additionally, these now return ssize_t results for error
checking.
2008-10-07 22:06:59 +02:00
Eric Wong
0d34815f6c Assert if we don't have song or song->url set
song objects cannot exist without a path or URL
2008-10-07 21:20:34 +02:00
Eric Wong
016af692d9 autotools: tidy up make dist
* Add missing headers in Makefile.am
* remove mp4ff.dsp (Win32 crap)
* Add scripts, m4, bs, autogen.sh to allow for hotfixes by the
  SCM-challenged.  (downloading the source via git is NOT a
  lightweight operation for everybody).
2008-10-06 18:54:12 +02:00
Eric Wong
f1c53fe0ed song: stop storing song_type
We already know if a song is a URL or not based on whether it
has parentDir defined or not.  Hopefully one day in the future
we can drop HTTP support from MPD entirely when an HTTP
filesystem comes along and we can access streams via open(2).
2008-10-06 18:52:13 +02:00
Max Kellermann
22e40b61cc song: don't make the struct packed
The "packed" attribute may have negative side effects on performance.
Remove the "packed" attribute, and increase the size of "song.url" to
a multiple of the machine word size.
2008-10-06 18:48:45 +02:00
Eric Wong
267b2cd6e6 song: use flex arrays to store song->url
Reduce the number of allocations we make, so there's less
pressure on the allocator and less overhead to keep track
of the allocations in.
2008-10-06 18:46:52 +02:00
Eric Wong
43761441c9 song: get rid of newNullSong()
It didn't save us any lines of code nor did it do anything
useful since we would overwrite everything anyways.
2008-10-06 18:43:10 +02:00
Eric Wong
dc245f389c song: call freeJustSong if newSong fails
There's no reason to scan the playlist for a song we
just allocated.
2008-10-06 18:41:41 +02:00
Eric Wong
d51da61b2d command: fix return status
This got broken when listHandlerFunc was removed.  Since we no
longer need it and it's confusing, remove processCommandInternal
and just use process_command.
2008-10-06 18:39:33 +02:00
Eric Wong
836dcc28c5 directory: reuse existing directory if found on update
Instead of allocating a new one, just reuse an existing
one if one is found when rereading the DB.  This is a small
makes the previous commit work on subdirectories
of the root music directory.

[1] "song: better handling of existing songs when rereading DB"
2008-10-06 18:37:13 +02:00
Eric Wong
fb4d55c5b3 tag: merge clearMpdTag into tag_free
avoid some redundant clearing logic as well, since the tag is
getting freed.
2008-10-06 18:35:41 +02:00
Eric Wong
8faf648784 command: get rid of specialized list handlers
commands should really not behave differently if they're issued
inside a command list or not; so stop having special handler
functions to deal with them.  "update" was the only command
that used this functionality and I changed that in the last
commit to serialize access.
2008-10-06 18:34:18 +02:00
Eric Wong
37a8239f44 directory: simplify list update handling logic
Now the "update" command can be issued multiple times regardless
of whether the client is in list mode or not.

We serialize the update tasks to prevent updates from trampling
over each other and will spawn another update task
once the current one is finished updating and reaped.

Right now we cap the queue size to 32 which is probably enough (I
bet most people usually run update with no argument anyways);
but we can make it grow/shrink dynamically if needed.  There'll
still be a hard-coded limit to prevent DoS attacks, though.
2008-10-06 18:32:27 +02:00
Eric Wong
700f18eee5 main_notify: define main_task so we can use it for assertions
It'll be easier to keep track of what code runs in what
task/thread this way.
2008-10-06 18:31:59 +02:00
Eric Wong
19a4803bc9 directory: streamline deletes
Instead of relying on the shortname, just pass the song pointer
to prevent redundant lookups during deletes.
2008-10-06 18:20:53 +02:00
Max Kellermann
6aec61637b pcm_utils: 24 bit support
Add support for 24 bit PCM samples to all functions.  Note that
pcm_convertAudioFormat() converts 24 bit samples to 16 bit; to
preserve full quality, support for "real" 24 bit conversion should be
added.
2008-09-29 17:26:07 +02:00
Max Kellermann
ac6bc76cdb pcm_utils: moved code to special 8/16 bit functions
Moved code into separate bit specific functions:
- pcm_volumeChange() -> pcm_volume_change_X()
- pcm_add() -> pcm_add_X()
- pcm_convertTo16bit() -> pcm_convert_8_to_16()
2008-09-29 17:25:45 +02:00
Max Kellermann
c85b570ad7 pcm_utils: pass only one buffer size to pcm_mix()
pcm_mix() might overflow the destination buffer if it is smaller than
the second buffer.  This is ok because the physical buffer size passed
by cross_fade_apply() is always big enough, but clutters pcm_mix()
with complicated length checks and contains a dangerous buffer
overflow pitfall.  Simplify pcm_mix()/pcm_add() and pass only the
smaller buffer size; let cross_fade_apply() do the memcpy().
2008-09-29 17:25:08 +02:00
Max Kellermann
6e21e24cae audio_output: added method pause()
pause() puts the audio output into pause mode: if supported, it may
perform a special action, which keeps the device open, but does not
play anything.  Output plugins like "shout" might want to play silence
during pause, so their clients won't be disconnected.  Plugins which
do not support pausing will simply be closed, and have to be reopened
when unpaused.

This pach includes an implementation for the shout plugin, which
sends silence chunks.
2008-09-29 16:43:55 +02:00
Max Kellermann
c13e8b5146 audio_output: added function audio_output_is_pending()
The function audio_output_is_pending() returns whether there is a
pending command.  This is useful for output plugins as a break
condition for longer loops.
2008-09-29 16:40:07 +02:00