Commit Graph

2255 Commits

Author SHA1 Message Date
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
Max Kellermann
de7cda1d6e use C99 struct initializers
The old struct initializers are error prone and don't allow moving
elements around.  Since we are going to overhaul some of the APIs
soon, it's easier to have all implementations use C99 initializers.
2008-09-29 15:55:17 +02:00
Max Kellermann
21d3d300fd decoder: renamed plugin methods
Why have a "_func" prefix on all method names?  Also don't typedef the
methods, there is no advantage in that.
2008-09-29 15:54:27 +02:00
Max Kellermann
a7651b9d30 assume stdint.h and stddef.h are available
Since we use a C99 compiler now, we can assert that the C99 standard
headers are available, no need for complicated compile time checks.
Kill mpd_types.h.
2008-09-29 15:53:53 +02:00
Max Kellermann
35d519625d song: converted "type" to enum
Having an enum type is much nicer than an anonymous integer plus CPP
macros.  Note that the old code didn't save any space by declaring the
variable 8 bit, due to padding.
2008-09-29 15:52:30 +02:00
Max Kellermann
e8e9438255 removed union const_hack
The union const_hack is only used at one place in the shout plugin.
Remove its global type declaration.
2008-09-29 15:51:31 +02:00
Max Kellermann
226d52b36f switch to C99 types, part II
Do full C99 integer type conversion in all modules which were not
touched by Eric's merged patch.
2008-09-29 15:49:29 +02:00
Eric Wong
0352766dca Switch to C99 types (retaining compat with old compilers)
Seeing the "mpd_" prefix _everywhere_ is mind-numbing as the
mind needs to retrain itself to skip over the first 4 tokens of
a type to get to its meaning.  So avoid having extra characters
on my terminal to make it easier to follow code at 2:30 am in
the morning.

Please report any new issues you may come across on Free
toolchains.  I realize how difficult it can be to build/maintain
cross-compiling toolchains and I have no intention of forcing
people to upgrade their toolchains to build mpd.

Tested with gcc 2.95.4 and and gcc 4.3.1 on x86-32.
2008-09-29 13:29:33 +02:00
Eric Wong
a4019f7d21 allow searching for albums with an empty tag
tfing wrote:
> I have quite some files with an empty album tag as they do not come
> from a particular album.
>
> If I want to look for those files and browse them, this happens:
> :: nc localhost 6600
> OK MPD 0.12.0
> find album ""
> ACK [2@0] {find} too few arguments for "find"
>
> I'd like to be able to browse those files in a client like gmpc.
> So these 2 items would have to be developed:
> - list album should report that some files have an empty tag
> - it should be possible to search for an empty tag with the find command

Patch-by: Marc Pavot
ref: http://musicpd.org/mantis/view.php?id=464
2008-09-29 13:18:49 +02:00
Eric Wong
5f0ed72c48 command: don't clobber next list value when preparsing
This only breaks "update" under list command mode and
no other commands.  This can be done more optimally
without the extra heap allocation via xstrdup(); but is
uncommon enough to not matter.
2008-09-29 13:18:35 +02:00
Eric Wong
11245dc119 directory: isRootDirectory() is a one-liner
Improving the signal to noise ratio...
2008-09-29 13:18:27 +02:00
Eric Wong
da79498afd directory: writeDirectoryInfo propagates errors
If a write failed, it's a good sign subsequent writes will fail,
too, so propgate errors all the way up the stack.
2008-09-29 13:17:52 +02:00
Eric Wong
4e15e292e0 directory: make it clear that DIRECTORY_MTIME is deprecated
A long time ago in an mpd far away...
2008-09-29 13:17:48 +02:00
Eric Wong
a0364d38d3 directory: remove "Mp3" references
MPD has supported more audio formats than just MP3
for over five years...
2008-09-29 13:17:42 +02:00
Eric Wong
9819890f1d playlist: deleteASongFromPlaylist takes a const Song *
We don't change the song pointer there, either.
2008-09-29 13:17:37 +02:00
Eric Wong
554f4a9fb9 songvec: songvec_delete takes a const Song pointer
We don't modify the Song when we delete it
2008-09-29 13:17:30 +02:00
Eric Wong
71b332601a directory: remove shortname arguments everywhere
It was a huge confusing mess of parameter passing around
and around.  Add a few extra assertions to ensure we're
handling parent/child relationships properly.
2008-09-29 13:17:23 +02:00
Eric Wong
8bb96d46e8 path: add mpd_basename() function
This is like basename(3) but with predictable semantics independent
of C library or build options used.  This is also much more strict
and does not account for trailing slashes (mpd should never deal with
trailing slashes on internal functions).
2008-09-29 13:16:48 +02:00
Eric Wong
5c516b8421 directory.h: remove directory_sigChldHandler decl
We no longer fork for directory updates, so we
no longer have children to reap.
2008-09-29 13:16:43 +02:00
Eric Wong
3b8bc33a04 directory: replace DirectoryList with dirvec
Small memory reduction compared to songvec since most users have
much fewer dirs than songs, but still nice to have.
2008-09-29 13:11:40 +02:00
Eric Wong
029f607e15 directory: remove unused CPP defines
We no longer for for updates
2008-09-29 12:17:20 +02:00
Eric Wong
6075119f0a songvec_free => songvec_destroy
"free" implies the songvec structure itself is freed,
which is not the case.
2008-09-29 12:17:13 +02:00
Eric Wong
5ec578119f directory.c: kill unnecessary includes 2008-09-29 12:16:57 +02:00
Eric Wong
52a0ea2dc5 directory: update playlist version if updated
If we updated the mpd metadata database; then there's a chance
some of those songs in the playlist will have updated metadata.
So be on the safe side and increment the playlist version number
if _any_ song changed (this is how all released versions of mpd
did it, too).

This bug was introduced recently when making "update" threaded.

Thanks to stonecrest for the bug report.
2008-09-29 12:15:16 +02:00
Max Kellermann
88aaa6b759 pcm_utils: added pcm_range()
Make the code more readable by moving the range checks to pcm_range().
gcc does quite a good job at optimizing it: the resulting binary is
exactly the same, although it contains a parametrized shift instead of
hard-coded boundaries.
2008-09-28 18:37:43 +02:00
Max Kellermann
5b5e46f5ef pcm_utils: added inline function pcm_dither()
Merge some code into an inline function, so we can optimize it later
only once.
2008-09-28 18:35:42 +02:00
Max Kellermann
75cba9343e output: fix the "outputenabled" value
Patch 9a5b5998 broke the "outputenabled" value of the "outputs"
response.  Make it print "1" if the output is enabled, "0" otherwise.
2008-09-28 18:34:10 +02:00
Max Kellermann
58554e14f9 notify: protect notify->pending with the mutex
There was a known deadlocking bug in the notify library: when the
other thread set notify->pending after the according check in
notify_wait(), the latter thread was deadlocked.  Resolve this by
synchronizing all accesses to notify->pending with the notify object's
mutex.  Since notify_signal_sync() was never used, we can remove it.
As a consequence, we don't need notify_enter() and notify_leave()
anymore; eliminate them, too.
2008-09-26 09:57:11 +02:00
Max Kellermann
323e86489f song: removed type SongList
SongList has been superseded by struct songvec.
2008-09-26 09:54:25 +02:00
Max Kellermann
e2a12deead audio_output: workaround for deadlock
During debugging, I found a deadlock between flushAudioBuffer() and
the audio_output_task(): audio_output_task() didn't notice that there
is a command, and flushAudioBuffer() waited forever in notify_wait().
I am not sure yet what is the real cause; work around this for now by
waking up non-finished audio outputs in every iteration.
2008-09-26 07:12:29 +02:00
Max Kellermann
05f66e04a4 update: send proper response to the client
Due to a merge error, I broke the function handleUpdate().  It did not
do anything for the global update, and it did not send a proper
response to the client.  This patch fixes both bugs.
2008-09-25 22:46:03 +02:00
Max Kellermann
9a5b599883 output: removed DEVICE_ON, DEVICE_OFF
To check whether a device is really on or off, we should rather check
audio_output.open, instead of managing another variable.  Wrap
audio_output.open in the inline function audio_output_is_open() and
use it instead of DEVICE_ON and DEVICE_OFF.
2008-09-24 07:25:07 +02:00
Max Kellermann
2b782b82ea output: semi-asynchronous playback
Send an output buffer to all output plugins at the same time, instead
of waiting for each of them separately.  Make several functions
non-blocking, and introduce the new function audio_output_wait_all()
to synchronize with all audio output threads.
2008-09-24 07:23:19 +02:00
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
ad92d9a894 command: fix command "addid"
With patch 8d2830b3, I broke "addid": it did not return the id of the
new song, because of a typo in the return condition (== instead of
!=).
2008-09-23 23:59:55 +02:00
Max Kellermann
d42959c5ce flac: removed FlacData.chunk_length
chunk_length can be converted to a local variable, because it is
always reset to 0 after it was used.
2008-09-23 23:59:55 +02:00
Max Kellermann
0c934f9d36 flac: merged flacSendChunk() into flac_common_write()
Since flacSendChunk() is a trivial function and is only used in one
location, move the code there.  The advantage is that calling
decoder_data() directly returns the decoder_command value, so we can
eliminate one decoder_get_command() call.
2008-09-23 23:59:55 +02:00
Max Kellermann
eeb3011070 flac: removed generic sample size support
Support for bit rates except 16 bits (and 8 bits on little endian) has
always been broken.  Since we added optimized functions for 8, 16,
24/32 bits, we can remove the generic flac_convert() function.
Instead of removing it, convert it to a wrapper function for
flac_convert_*().
2008-09-23 23:59:55 +02:00
Max Kellermann
19971be307 flac: added special functions for 8 and 32 bit
Same optimization for 8 and 32 bit files, like the previous patch for
16 bit.  Along the way, this patch adds 24 bit FLAC support!
2008-09-23 23:59:55 +02:00
Max Kellermann
8c2bde70b0 flac: added optimized converter for 16 bit
flac_convert_16() runs a lot faster than the generic (and quite buggy)
function flac_convert().  flac_convert_16() is only used for
non-stereo files, since there is already flac_convert_stereo16().
2008-09-23 23:59:55 +02:00
Max Kellermann
7486c15088 flac: use signed integers in flac_convert_stereo16()
By mistake, I casted the sample value to uint16_t, which is wrong.
This patch simplifies the code by using a int16_t pointer instead of
casting to int16_t* every time.
2008-09-23 23:59:54 +02:00
Max Kellermann
8bcbe90b25 flac: moved code from flacWrite() to _flac_common.c
There is still a lot of duplicated code in flac_plugin.c and
oggflac_plugin.c.  Move code from flac_plugin.c to _flac_common.c, and
use the new function flac_common_write() also in oggflac_plugin.c,
porting lots of optimizations over to it.
2008-09-23 23:59:54 +02:00
Max Kellermann
aac5f42698 flac: assume the buffer is empty in flacWrite() II
The previous patch on this topic was incomplete: it still added
data->chunk_length when calling flac_convert().  Remove this, too.
2008-09-23 23:59:54 +02:00
Max Kellermann
128d8c7c15 audio_format: added audio_format_sample_size()
The inline function audio_format_sample_size() calculates how many
bytes each sample consumes.  This function already takes into account
that 24 bit samples are 4 bytes long, not 3.
2008-09-23 23:59:54 +02:00
Eric Wong
e4f5d6bdf4 alsa: re-enable-nonblocking, but sleep if busy
Instead of letting ALSA block for us (and potentially allowing
something stupid on certain hardware or drivers), we do the
sleeping ourselves.  We calculate the sleep to be a fraction of
period_time to avoid oversleeping (and thus audible skipping).
2008-09-23 23:59:54 +02:00
Eric Wong
ef35926083 songvec: avoid free(NULL)
Potentially broken free() implementations don't like it
2008-09-23 22:38:43 +02:00
Eric Wong
74b34f7b61 directory: fix leak introduced with threaded update
Use freeList() instead of free() to free all elements in
the list.
2008-09-23 22:38:39 +02:00
Eric Wong
260e1a9037 Remove EINTR checking for open(2)
open(2) should only interrupt on "slow" devices, afaik...

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

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

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

      remove --update-db option

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Furthermore, the thread-communication via condition variables
between threads sharing audio formats already results in memory
barriers.
2008-09-07 19:14:50 +02:00