The decoder_plugin struct is used by both the MPD core and the decoder
plugin implementations. Move it to a shared header file, to minimize
header dependencies.
If mpd.conf specifies a user, and MPD is invoked by exactly this user,
ignore the "user" setting. Don't bother to look up its groups and
don't attempt to change uid, it won't work anyway.
Use delete_directory() for removing sub directories instead of
dirvec_clear(). This ensures that all memory occupied by
subdirectories of deleted directories is freed.
When a directory is deleted, MPD deleted only the directory from the
database; it did not bother to walk the full tree to free all memory
and to remove deleted songs from the playlist. Replace a
dirvec_delete() with delete_directory().
When you change the filesystem charset, discard the old database file
and create a new one. The old database file will most likely contain
stale or invalid information.
There are a few problems left in this plugin:
- fluidsynth decodes in real time, while MPD prefers to buffer as
quickly as possible; as a workaround, this plugin uses a timer
object to synchronize with real-time playback
- I don't know yet how fluidsynth tells me when the song has ended
- the "soundfont" configuration setting is not yet documented, and it
will likely change soon (in favor of a per-decoder configuration
block)
When MPD is not playing, it may still remember which is the "current"
song. When you switch to "random" mode, MPD will always start playing
exactly this song. This defies the goal of "random" mode a little.
Clear the "current" song when MPD is not playing during the "random"
mode switch.
The output_command library provides a command interface to the audio
outputs. It assumes the input comes from an untrusted source
(i.e. the client) and verifies all parameters.
In addition to audio_format_valid(), provide functions which validate
only one attribute of an audio_format. These functions are reused by
audio_format_parse().
Added audio_format_parse() in a separate library, with a modern
interface: return a GError instead of logging errors. This allows the
caller to deal with the error.
When MPD explicitly starts playing, ignore the "REOPEN_AFTER" timeout.
This timeout was useful when MPD attempted to reopen a failed device
over and over, but it confuses users when they explicitly tell MPD to
start playing, while MPD insists to wait for the 10 seconds to pass.
Fix a memory leak: it was not guaranteed that pcm_convert_deinit() was
called for each pcm_convert_init(). This patch always (de)initializes
the pcm_convert library when the audio_output.open flag is flipped.
Pass the music chunk as a "const void *" to the encoder, instead of a
"const char *". Actually, both encoders currently expect 16 bit
samples, passing a 8-bit character is rather pointless.
The crossfading code shouldn't depend on the audio output code. Pass
the current audio format to cross_fade_calc() and let it compare
directly, instead of using isCurrentAudioFormat().
When MPD is stopped, but the last song is still the "current song",
and you delete it, playlist->current is not updated, and becomes an
invalid value. Fix this by catching "!playlist->playing &&
playlist->current == (int)songOrder".
audio_output_config_count() returns the number of audio outputs in the
configuration file. It is only used by initAudioDriver(). The public
function audio_output_count() now returns audioOutputArraySize.
When we reset pc.next_song if there is no song queued, this might
cause a race condition: the next song to be played is cleared, while
pc.command was already set. Clear the "next_song" only if there is a
song queued for the current do_play() invocation.
If a new song is queued before calling playerSeek(), then the player
and the playlist enter an inconsistent state, because the player
discards the playlist's "queued" song in favor of the seeked song.
Call playlist_update_queued_song() after playerSeek().
After a player command (successful or not), reset pc.next_song,
because the queue is supposed to be empty then. Otherwise,
playlist.queued and pc.next_song may disagree, which triggers an
assertion failure.
Commit f78cddb4 introduced a regression: after a song was moved, the
order array was not updated (in random mode). This caused MPD to
think the "current" song has changed when you moved something to the
position of the current song.
Always assume the buffer is empty before calling the encoder. Always
flush the buffer immediately after there has been added something.
This reduces the risk of buffer overruns, because there will never be
a "rest" in the current buffer.
The non-blocking mode of libshout is sparsely documented, and MPD's
implementation had several bugs. Also removed connect throttling
code, that is done by the MPD core since 0.14.
After the state file has been loaded, the playlist version is still
"1", and "plchanges 1" returns the whole playlist. Fix this by
increasing the playlist version after the state file has been loaded.
Don't call syncPlaylistWithQueue() in nextSongInPlaylist() and
previousSongInPlaylist(). This is a relic from the time when there
was no event, and was a workaround to the timing problem.
Export the "g_playlist" variable, and pass it to all playlist
functions. This way, we can split playlist.c easier into separate
parts. The code which initializes the singleton variable is moved to
playlist_global.c.
Before every operation which modifies the playlist, remember a pointer
to the song struct. After the modification, determine the "next song"
again, and if it differs, dequeue and queue the new song.
This removes a lot of complexity from the playlist update code, and
makes it more robust.
The "current" variable is used for calculating the seek destination,
and was declared as "int". With very long song files, the 32 bit
integer can overflow. ffmpeg expects an int64_t, which is very
unlikely to overflow. Switch to int64_t.
If avcodec_decode_audio2() returns no output for an AVPacket,
libavcodec may buffer some data, and return a larger chunk of output
later. This patch disables a lot of bogus warnings.
Output the name of the codec as a debug message. During my tests,
ffmpeg never filled this struct member, but it may do so in the past,
and this debug message might become helpful.
The shout_mp3 encoder had two bugs: when no song was ever played, MPD
segfaulted during cleanup. Second bug: memory leak, each time the
shout device was opened, lame_init() was called again, and
lame_close() is only called once during shutdown.
Fix this by shutting down LAME each time the clear_encoder() method is
called.
When the update thread is started before MPD has forked (for
daemonization), it is killed, because threads do not survive a fork().
This induces an inconsistent state where MPD won't start any update
thread at all, because it thinks the thread is already running.
Move the "while" loop which checks for commands to the caller
ao_pause(). This simplifies the pause() method, and lets us remove
audio_output_is_pending().
If no ports are configured, don't overwrite the (NULL) configuration
with the port names of the first JACK server. If the server changes
after a JACK reconnect, MPD won't attempt to auto-detect again.
Currently, the JACK plugin manipulates the audio_format struct which
was passed to the open() method. This is very likely to break,
because the plugin must not permanently store this pointer. After
this patch, MPD ignores sample rate changes. It looks like other
software is doing the same, and I guess this is a non-issue.
This patch converts the audio_format pointer within jack_data into a
static audio_format struct.
Hi -
independently of libmikmod's other problems - there seems
to be a problem in mpd's wrapper: MikMod_Exit() is called
after the first file is decoded, which frees some ressources
within the mikmod library. An attempt to play a second file
leads to a crash. The appended patch fixes this for me.
(I don't know what the "dup" entry is good for - someone
who knows should review that too.)
best regards
Matthias
[mk: removed 3 more MikMod_Exit() invocations]
When there are duplicate slashes in the song paths, eliminate them;
example:
/var/lib/mpd/music//foo.mp3
becomes:
/var/lib/mpd/music/foo.mp3
The slash is only detected at the border between the music_directory
and the local part.
When the user configures a music_directory with a trailing slash, it
may break playlist loading, because MPD expects a double slash. Chop
off the trailing slash.
ffmpeg_tag_internal() does not look for a few tags that mpd
supports. Most noteably:
comment -> TAG_ITEM_COMMENT -> Description
genre -> TAG_ITEM_GENRE -> WM/Genre (not WM/GenreID)
year -> TAG_ITEM_DATE -> WM/Year
I *think* that this is the last of the tags that AVFormatContext() in
ffmpeg supports that mpd also uses.
Make those two methods optional to implement, and let input_stream.c
provide fallbacks. The buffer() method will be removed one day, and
there is now only one implementation left (input_curl.c).
The open_stream() method opens the input_stream. This allows the
archive plugin to do its own initialization, and it also allows it to
use input_stream.data. We can remove input_stream.archive now, which
was unnatural to have in the first place.
Preparation for supporting other channel numbers than stereo: use
loops instead of duplicating code for the second channel. Most
likely, gcc will unroll these loops, so the binary won't be any
different.
This patch implements the MMS protocol, by using libmms. It is quite
experimental: it does not support seeking yet, and it is currently
using synchronous I/O, which causes MPD to hang while waiting for the
server.
When the playlist is cleared, pc.errored_song is also cleared. This
causes pc_errored_song_uri() to crash, because it assumes that
pc.errored_song is set. Reset pc.error to fix that assumption.
When waiting for free space in the ring buffer, the JACK plugin
sleeped 10ms until there is enough space. This delay was too large
for low-latency setups (<10ms), and created a lot of xruns. Work
around that by reducing the sleep time to 1ms.
A proper solution for this would be to use an event based approach,
and we will do it, just not now.
When the connection failed once, you had to restart MPD, because it
never cleared the jack_data.shutdown flag. Instead, it refused to
play anything "because there is no client thread" (which is wrong at
that point).
GIOChannel is more portable than raw read()/write() calls. We're
using GIOChannel anyway, because we need it for plugging the client
into the GLib main loop.
Configure the GIOChannel to the bare minimum: no character set, no
buffering.
On some platforms, g_free() must be used for memory allocated by
GLib. This patch intends to correct a lot of occurrences, but is
probably not complete.
Both methods are always called together. There is no point in having
them separate. This simplifies the code, because the old configure()
method could be called more than once, and had to free old
allocations.
Reimplemented the legacy mixer configuration: copy the deprecated
configuration values into the audio_output section. Don't configure
the mixers twice (once for the audio_output, and a second time for the
legacy values).
This requires volume_init() to be called before initAudioDriver().
Return the default value in the conf_get_block_*() functions when
param==NULL was passed.
This simplifies a lot of code, because all initialization can be done
in one code path, regardless whether configuration is present.
Two bugs here led to a large number of interrupts being generated on the
sound card when ALSA output is being used. Because we specify no default
period_time, the sound card gives us 3000 interrupts/sec rather than a more
sane 20 or 30. This completes the revert of dd7711 already started by
4ca24f.
The larger bug was in the change to config_get_block_unsigned() and using 0
as the default value for both 'buffer_time' and 'period_time'. This means
any pre-setting of these options in newAlsaData() gets wiped out. Add a new
default for period_time, and ensure default values for buffer_time and
period_time are used if none are provided by the user.
Signed-off-by: Dan McGee <dan@archlinux.org>
[mk: set defaults in newAlsaData() to fix auto-configuration; renamed
"_MS" back to "_US" because ALSA expects microseconds, not milliseconds]
Signed-off-by: Max Kellermann <max@duempel.org>
Added all important id tags from the MusicBrainz wiki:
http://musicbrainz.org/doc/MusicBrainzTag
This should automatically enable its suport in the vorbis and flac
decoder plugins.
The input_stream API sets size to -1 when the size of the resource is
not known. The modplug decoder checked for size==0, which would be an
empty file.
You are allowed to call decoder_read() with decoder==NULL. It is a
convenience function provided by the decoder API. Don't manually fall
back to input_stream_read().
When the playlist was loaded from the state file, the order numbers
were the same as the positions. In random mode, we need to shuffle
the queue order. To accomplish that, call setPlaylistRandomStatus()
at the end of readPlaylistState(), and do a fresh shuffle.
When MPD is not playing while in random mode, and the client issues
the "clear" command, MPD crashes in stopPlaylist(), or more exactly,
in queue_order_to_position(-1). Exit from stopPlaylist() if MPD isn't
playing.
PlaylistInfo() (notice the capital 'P') sends a stored playlist to the
client. Move it to a separate library, where all the code which glues
the playlist and the MPD protocol together will live.
The playlist.c source is currently quite hard to understand. I have
managed to wrap my head around it, and this patch attempts to explain
it to the next guy.
The function playPlaylistIfPlayerStopped() is only called when the
player thread is stopped. Converted that runtime check into an
assertion, and remove one indent level.
One of the previous patches removed the "random" mode check from
nextSongInPlaylist(), which caused a shuffle whenever MPD wrapped to
the first song in "repeat" mode. Re-add that "random" check.
In playPlaylist(), the second "song==-1 && playing" check can never be
reached, because at this point, the function has already returned
(after unpausing).
When a song is deleted, start playing the next song immediately,
within deleteFromPlaylist(). This allows us to remove the ugly
playlist_noGoToNext flag, and the currentSongInPlaylist() function.
By calling queue_next_order() before playlist.current is invalidated
(by the deletion of a song), we get more robust results, and the code
becomes a little bit easier. incrPlaylistCurrent() is unused now, and
can be removed.