Commit Graph

11547 Commits

Author SHA1 Message Date
Max Kellermann
5cb603983e alsa/NonBlock: throw on snd_pcm_poll_descriptors_revents() error
This function is sparsely documented and a look at the bluez-alsa
source code shows that implementations make undocumented assumptions
on the `struct pollfd` array parameter which can lead to strange
effects.
2018-12-04 18:00:52 +01:00
Max Kellermann
4b7078297d db/upnp: use the generic ::CollectUniqueTags() function
This function implements the "group" feature on top of the
Database::Visit() method.
2018-11-19 20:08:10 +01:00
Max Kellermann
841694ccf2 db/Interface: document CollectUniqueTags() 2018-11-19 19:40:00 +01:00
Max Kellermann
12f4a8255a Main: use DatabasePlugin::RequireStorage() 2018-11-19 19:39:37 +01:00
Max Kellermann
bda77ffc5b db/Interface: remove IsPlugin(), use dynamic_cast instead 2018-11-19 19:38:20 +01:00
Max Kellermann
ed9ece5ea3 db/Interface: make the constructor protected 2018-11-19 19:38:20 +01:00
Max Kellermann
ce49d99c2f check.h: remove obsolete header
Since we switched from autotools to Meson in commit
94592c1406, we don't need to include
`config.h` early to properly enable large file support.  Meson passes
the required macros on the compiler command line instead of defining
them in `config.h`.

This means we can include `config.h` at any time, whenever we want to
check its macros, and there are no ordering constraints.
2018-11-19 16:33:49 +01:00
Max Kellermann
2e450bbf95 src/thread/meson.build: detect pthread_setname_np()
This compile-time check got lost during the Meson transition.
2018-11-19 16:33:14 +01:00
Max Kellermann
303b3071e4 db/UniqueTags: remove pure attribute because function may throw 2018-11-19 11:32:53 +01:00
Max Kellermann
eb6d5f34fc db/UniqueTags: include cleanup 2018-11-19 11:11:45 +01:00
Max Kellermann
4cdcaa8630 output/alsa: don't call snd_pcm_drain() if nothing was written
Works around a problem where MPD goes into a busy loop because
snd_pcm_drain() always returns `-EAGAIN` without making any progress
(fixes #425).

This problem was triggered by snd_pcm_drain() after snd_pcm_cancel()
and snd_pcm_prepare(), but without submitting any data with
snd_pcm_writei().

I believe this is a kernel bug: in non-blocking mode, the kernel's
snd_pcm_drain() function returns early.  In this mode, it only checks
whether snd_pcm_drain_done() has been called already, but
snd_pcm_drain_done() is never called if no data was submitted.

In blocking mode, the following `for` loop detects this condition, so
snd_pcm_drain_done() is not necessary, but without this extra check,
we get `-EAGAIN` forever.
2018-11-16 12:49:37 +01:00
Max Kellermann
436ba3c96c output/alsa: drain the whole ring_buffer, not just one period
This fixes a problem which caused a failure with snd_pcm_writei()
because snd_pcm_drain() had already been called in the previous
iteration.  This commit makes sure that snd_pcm_drain() is only called
after the final snd_pcm_writei() call.

This fixes discarded samples at the end of playback.
2018-11-14 13:35:17 +01:00
Max Kellermann
5d12f52873 output/alsa: clear error after reopening device
When a playback error has occurred, MPD would never recover until one
restarts MPD.
2018-11-14 13:20:54 +01:00
Max Kellermann
a8bf8ede01 event/Thread: reduce the RTIO timer slack to 10us
MPD's default is 100ms, which is too long for the real-time I/O
thread.  The OutputThread has 100us, but the real-time I/O thread
might have tighter deadlines.

This change has currently no effect (I believe), because nobody uses
timers on the RTIO thread.
2018-11-14 12:11:57 +01:00
Max Kellermann
8682183bc3 LogInit: default to journal if MPD was started as systemd service 2018-11-14 12:07:22 +01:00
Max Kellermann
b477f86c92 output/alsa: don't lock the mutex in CancelInternal()
CancelInternal() doesn't need to be protected because it is called
synchronously from Cancel().
2018-11-14 11:50:51 +01:00
Max Kellermann
020371f145 output/alsa: wake up the client thread after generating silence
Fixes a theoretical race condition which could occur in Drain() (but
was extremely unlikely).
2018-11-14 11:48:55 +01:00
Max Kellermann
ccafe3f3cf output/alsa: don't generate silence if ALSA-PCM buffer has enough data
If our `ring_buffer` is smaller than the ALSA-PCM buffer (if the
latter has more than the 4 periods we allocate), it can happen that
the start threshold is crossed and ALSA switches to
`SND_PCM_STATE_RUNNING`, but the `ring_buffer` is empty.  In this
case, MPDD will generate silence, even though the ALSA-PCM buffer has
enough data.  This causes stuttering (#420).

This commit amends an older workaround for a similar problem (commit
e08598e7e2) by adding a snd_pcm_avail()
check, and only generate silence if there is less than one period of
data in the ALSA-PCM buffer.

Fixes #420
2018-11-14 11:17:59 +01:00
Max Kellermann
3830748de5 output/alsa: clear the period_buffer in LockCaughtError()
The method Cancel() assumes that the `period_buffer` must be empty
when `active==false`, but that is not the case when Play() fails.

Of course the assertion in Cancel() is not 100% correct, but I decided
to rather fix this in LockCaughtError() because the `period_buffer`
should only be accessed from within the RTIO thread, and this is the
only code path where `active` can be set to `false` with a non-empty
`period_buffer`.

Fixes #423
2018-11-14 10:24:08 +01:00
Max Kellermann
1a43f5145d output/alsa: throw on snd_pcm_writei() error while draining
This implements real error handling, and avoids calling
CancelInternal() from this code path.
2018-11-14 10:08:29 +01:00
Max Kellermann
7f143a83c1 output/alsa: fix wrong use of errno
alsa-lib doesn't set errno, it returns errors as negative integers.
2018-11-14 10:07:23 +01:00
Max Kellermann
6ccc254179 output/alsa: throw after snd_pcm_drain() error 2018-11-14 10:04:10 +01:00
Max Kellermann
7db2450447 output/alsa: refactor the drain EAGAIN workaround 2018-11-14 10:00:50 +01:00
Max Kellermann
6c2a6a65e0 output/alsa: remove snd_pcm_state() check from DrainInternal()
This check was added 9 years ago in commit
4dc25d3908 to work around a dmix bug
which I assume has been fixed long ago.

Removing this fixes another corner case: if draining is requested
before the start threshold is reached, the PCM is still in
SND_PCM_STATE_PREPARED but not yet SND_PCM_STATE_RUNNING, which means
the submitted data will never be played.  This corner case is
realistic when playing songs shorter than the ALSA buffer (if the
buffer is very large).
2018-11-14 09:48:24 +01:00
Max Kellermann
4247a757b3 output/alsa: call snd_pcm_prepare() if draining is requested early
This fixes a corner case which has probably never occurred and
probably never will: if Cancel() is called, and then Play() followed
by Drain(), the plugin should really play that data.  However
currently, this never happens, because snd_pcm_prepare() is never
called.
2018-11-14 09:43:14 +01:00
Max Kellermann
060908d5c4 song/Filter: add operator "contains"
Closes #410
2018-11-12 12:49:01 +01:00
Max Kellermann
228bf7eb09 output/thread: cancel the AudioOutputSource() instead of closing it
This fixes the assertion failure due to calling
AudioOutputSource::Close() twice.
2018-11-12 12:24:25 +01:00
Max Kellermann
5eaf2b8fc3 output/control: always close the AudioOutputSource in RELEASE
Fixes a crash bug with `always_on` outputs which occurs because the
`AudioOutputSource` still has a pointer to an outdated `MusicChunk`.

Fixes #415
2018-11-12 12:21:59 +01:00
Max Kellermann
e097fef79e output/control: add command RELEASE
With the new command, the decision to pause or close the output moves
into the output thread.
2018-11-12 12:09:37 +01:00
Max Kellermann
9a813cd3b1 output/Thread: update comment 2018-11-12 12:09:02 +01:00
Max Kellermann
1c60c8e014 output/Filtered: catch Drain() exceptions in CloseOutput() 2018-11-12 12:05:54 +01:00
Max Kellermann
eddda95900 output/interface: document that Drain() may throw 2018-11-12 12:04:42 +01:00
Max Kellermann
72184dccfc song/StringFilter: support regular expressions with "=~" and "!~"
This feature requires `libpcre`.
2018-11-11 12:55:35 +01:00
Max Kellermann
fee75dc766 {output,mixer}/alsa: use snd_pcm_poll_descriptors_revents()
This call was missing, causing very high CPU usage when the ALSA
output plugin was used with dmix.

Closes #391
2018-11-11 12:37:29 +01:00
Max Kellermann
ba5c856f15 events/MultiSocketMonitor: add method ForEachResult() 2018-11-11 12:37:28 +01:00
Max Kellermann
12308a0f55 lib/alsa/NonBlock: move the functions into a class managing the state 2018-11-11 12:37:25 +01:00
Max Kellermann
a958abde2f Merge branch 'fix_362' of git://github.com/miccoli/MPD 2018-11-11 12:37:13 +01:00
Max Kellermann
583208db7e output/httpd: fix nullptr dereference crash bug
When `metadata_sent` is `false`, the plugin assumes there is metadata
which must be sent, even if no metadata page was passed to the plugin.
Initializing it to `true` avoids dereferencing this `nullptr`.

Fixes #412
2018-11-08 09:37:18 +01:00
Max Kellermann
7b5ba15170 song/Filter: move code to ParseStringFilter() 2018-11-08 00:02:10 +01:00
Max Kellermann
d5e0d49f86 song/{Tag,Uri}SongFilter: pass StringFilter&& to constructor 2018-11-07 23:57:42 +01:00
Max Kellermann
73b22d82aa song/StringFilter: move negated flag from containing class 2018-11-07 23:47:31 +01:00
Max Kellermann
db51cc4e02 lib/zlib/meson.build: add zlib_dep to declare_dependency
Fixes potential compiler error when zlib is installed in a
non-standard directory.
2018-11-07 23:32:23 +01:00
Max Kellermann
ad597a8ff0 lib/zlib/meson.build: define ENABLE_ZLIB
Fixes #414
2018-11-07 23:24:58 +01:00
Max Kellermann
b1fe105904 output/Source: reset current_chunk in Open()
If the output is already open, the `current_chunk` pointer may be
bogus and out of sync with `SharedPipeConsumer::chunk`, leading to an
assertion failure in `SharedPipeConsumer::Consume()`.

Fixes #411
2018-11-07 00:17:48 +01:00
Max Kellermann
451b142e3a player/Thread: finish decoder startup before checking the buffer
This fixes a valgrind warning because `buffer_before_play`
initialization needs to know the audio format from the decoder.
2018-11-06 23:52:26 +01:00
Max Kellermann
98985c03b0 check.h: remove obsolete ENABLE_LARGEFILE check
Meson always enables large file support on the compiler command line,
thus config.h doesn't need to be included anymore.  We'll remove the
whole `check.h` header soon.

Closes #409
2018-11-05 21:25:59 +01:00
Max Kellermann
793fd8c479 decoder/ffmpeg: eliminate GetSampleFormat() 2018-11-04 22:36:17 +01:00
Max Kellermann
6c602811df decoder/ffmepg: fill AudioFormat from AVCodecContext, not AVCodecParameters
`AVCodecParameters` contains values from the codec detected by
avformat_find_stream_info(), but after avcodec_open2(), a different
codec might be selected with a different `AVSampleFormat`.  This leads
to misinterpretation of data returned from FFmpeg, leading to random
noise or silence.

This was observed with FFmpeg 4.0.2 and a TS container file containing
MP2.  A mp3-float codec was detected returning `AV_SAMPLE_FMT_FLTP`,
but finally the `mpegaudiodec_fixed.c` was used, returning
`AV_SAMPLE_FMT_S16`.

By using the audio format from `AVCodecContext`, we ensure that MPD
and FFmpeg always agree on the actual audio format in the buffer.

This removes the FFmpeg bug workaround from commit e1b032cbad which I
assume is obsolete after 7 years.

Fixes #380
2018-11-04 22:30:50 +01:00
Stefano Miccoli
6d48a5684a clamp 'set_normalized_volume' to valid values also for ALSA softvol
ensure that valid mixer values are set also when the ALSA driver
does not report a valid dB range ('set_raw' fallback)

correct a bug in which volume is assumed to lie in [0..100]
instead of [0..1]
2018-11-04 22:21:56 +01:00
Max Kellermann
bd115a4008 decoder/ffmpeg: use AtScopeExit() to call av_packet_unref() 2018-11-04 22:01:33 +01:00