Commit Graph

157 Commits

Author SHA1 Message Date
Rosen Penev
7f10e7a610
fix implicit-fallthrough warnings under clang
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-16 00:12:38 -07:00
Max Kellermann
1e421cbcb2 Merge remote-tracking branches 'neheb/patch-2', 'neheb/con', 'neheb/cons', 'neheb/guruhg', 'neheb/r12R3', 'neheb/fefgheh' and 'neheb/rhgerg3453' 2020-02-05 19:36:01 +01:00
Rosen Penev
a3963de668
[clang-tidy] change integer prefixes to uppercase
Found with readability-uppercase-literal-suffix

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-04 15:20:50 -08:00
Rosen Penev
1923cf3844
remove redundant const qualification
Found with readability-const-return-type

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-04 15:16:28 -08:00
Rosen Penev
b64fdae938
[clang-tidy] use override instead of virtual
Found with modernize-use-override

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-01-31 21:27:26 -08:00
Max Kellermann
2817bf9e95 copyright year 2020 2020-01-18 19:23:49 +01:00
Max Kellermann
d663f81420 include cleanups (powered by iwyu) 2019-07-05 09:59:58 +02:00
Max Kellermann
0a32634d8f output/alsa: check ring buffer space before writing to it
Pass only the amount of data to PcmExport::Export() when its full
output fits into the ring buffer.  Using only a part of the
PcmExport::Export() result may cause data corruption because
PcmExport's internal state may contain partial blocks which would need
to be rolled back when only some of its output data was used.

As a side effect, this fixes an assertion failure because
PcmExport::CalcInputSize() considered partial block data and could
cause Play() to return a number larger than the "size" parameter.
2019-07-04 12:47:10 +02:00
Max Kellermann
b12fc3c60d output/alsa: throw unexpected snd_pcm_writei() errors
If snd_pcm_writei() fails, throw an error and stop playback instead
of going into an endless busy loop.
2019-07-04 12:46:18 +02:00
Max Kellermann
412b04be58 output: allow throwing any exception 2019-07-03 22:10:26 +02:00
Max Kellermann
557098644b release v0.21.11
-----BEGIN PGP SIGNATURE-----
 
 iQJEBAABCgAuFiEEA5IzWngIOJSkMBxDI26KWMbbRRIFAl0cqqwQHG1heEBtdXNp
 Y3BkLm9yZwAKCRAjbopYxttFErtoD/0Qmma/ltv/D7+m+ZugDLUejxJ/SGEPJNVS
 To2yy87TqwcgRcmrlwp05epxxqm54LmE8z3748iIS76zBySc4lA8OHWCNCNs0lrc
 gbUOmUM9ZE89oXppEfjLlqIofSJVLw8rY+8RMtybKeKaJ3/4JlDySMw92UuZ3LMJ
 woqAZPUOPGYsT1KBjblWsRYkn5broOZ3m2zt6e5r09ICudKQjvS6gXT3wmNqmDEU
 cos2taYNGyi42ywVJzeAPVOO/MecS+WXZIIR0y5TvslDhKkTHIo2SS1qcNM2tCdg
 c5s+vQUtZkFmKK3fr4H861cWQelRbBFY4Fy/Shrz2FMZj7eUExH/eXaxX8I7S8tX
 f0H2y944AXwlFJrIQylnSgx4x9E+ye/Mqc8O4hmSA9KHfrWDWegcbB5S2v6zt1e9
 BmiWClH5Ts1beNmT5F9nExFLZjQzxwFTsm44HJhOK+poULRo+WQLllcAsCRjNw8s
 7EzPF/UmBcydeyWYmoPhXiexAFaIDx9B+n2SlgekdvxeneXHZMskkpyysLNVde3o
 1jXH0dBdm8rj8Xp2zm9t5yjnCy2iKPO5oVdZ+keTM9olG3Er+ar5ofT78n0xbEFW
 h7PikktbqWYeF01QjfSsHO7bhOVkvLtMNLZG1gtBGMI5qUWdnC/2HbTZWRHVeAKe
 wFxdx2MBwg==
 =4kRo
 -----END PGP SIGNATURE-----

Merge tag 'v0.21.11'

release v0.21.11
2019-07-03 15:36:45 +02:00
Max Kellermann
f780ac418a output/alsa: log when generating silence due to slow decoder
MPD used to do that when this code lived in the player thread, but it
was removed by commit 98a7c62d7a4f716d90af6d78e18d1a3b10bc54b3; and
the replacement code in the ALSA output plugin didn't have it.
2019-06-28 18:15:30 +02:00
Max Kellermann
61a72a5d13 output/alsa: schedule a timer to generate silence
Without this timer, DispatchSockets() may disable the
MultiSocketMonitor and if Play() doesn't get called soon, it never
gets a chance to generate silence.  However if Play() gets called,
generating silence isn't necessary anymore...

Resulting from this misdesign (added by commit ccafe3f3cf in 0.21.3),
the silence generator didn't work reliably.
2019-06-28 18:04:49 +02:00
Max Kellermann
0c0a354753 output/alsa: add a new flag "waiting" for xrun management
In DispatchSockets(), when there was not enough data, but enough for
current playback, the method would disable the "active" flag so the
next Play() call would re-enable the MultiSocketMonitor.

This was an abuse of the flag which could result in a crash
in Cancel(), because that method asserts that the period_buffer is
empty, which it may be not.

The solution is to add anther flag called "waiting" which shares some
behavior with the old flag.
2019-06-28 18:04:49 +02:00
Max Kellermann
3c5f860fb8 output/alsa: Cancel() also affects "active" (documentation) 2019-06-28 18:04:49 +02:00
Max Kellermann
3da1fa88d0 output/alsa: fix comment typo 2019-06-28 18:04:49 +02:00
Max Kellermann
fac15aaffb output/alsa: fix comment typo 2019-06-28 14:39:54 +02:00
Max Kellermann
a92aa0bedc output/alsa: use IsCleared() instead of IsDrained() in DrainInternal()
Really drain all data from the period_buffer in any case.
2019-06-28 09:30:33 +02:00
Max Kellermann
d66f5a8590 output/alsa: replace PeriodBuffer::IsEmpty() with IsCleared()
This assertion is not about whether all data has been consumed, but
about whether there has been any data at all.
2019-06-28 09:29:18 +02:00
Max Kellermann
30ca6b8881 Merge branch 'v0.21.x' 2019-06-28 09:28:04 +02:00
Max Kellermann
c926021599 output/alsa: always redo DrainInternal() after writing
Draining isn't finished just because the period_buffer has run empty.
It is only finished after snd_pcm_drain() has succeeded.
2019-06-28 09:10:16 +02:00
Max Kellermann
543776d9c9 output/alsa: check PCM state before calling snd_pcm_drain()
Apparently, if snd_pcm_drain() returns EAGAIN, it does not actually
want to be called again; the next call will snd_pcm_drain() will also
return EAGAIN, forever, even though the PCM state has meanwhile
switched to SND_PCM_STATE_SETUP.  This causes a busy loop; to fix
this, we should always check snd_pcm_state() to see if draining is
really required.
2019-06-28 08:55:25 +02:00
Max Kellermann
cf631fca50 output/alsa: check GetFrames()>0 instead of IsEmpty() in WriteFromPeriodBuffer() 2019-06-27 21:59:43 +02:00
Max Kellermann
f0ac63d5af output/alsa: DrainInternal() ignores postponed partial frame 2019-06-27 21:23:28 +02:00
Max Kellermann
c1eb0583c4 output/alsa: add "full" assertion to WriteFromPeriodBuffer() 2019-06-27 21:22:52 +02:00
Max Kellermann
549faa8a9c output/alsa: add full check before calling FillWithSilence() 2019-06-27 21:20:38 +02:00
Max Kellermann
8f6c750064 output/alsa: improve silence generator test in DrainInternal()
There cannot be partial frames in the buffer, so we don't need
GetPeriodPosition(); it's enough to check whether head has been moved
in this period.
2019-06-27 21:17:37 +02:00
Max Kellermann
9fc1668de3 output/alsa: hold back snd_pcm_writei() until period_buffer is full
This gives MPD more control, because attempts to avoid having partial
periods in the ALSA period buffer.  For example, this means that
DrainInternal() doesn't need to generate silence to fill the partial
period.
2019-06-27 15:40:07 +02:00
Max Kellermann
2f243f2295 pcm/Export: rename GetFrameSize() to GetOutputFrameSize() 2019-06-26 15:46:49 +02:00
Max Kellermann
e69fd0300a pcm/Export: rename CalcSourceSize() to CalcInputSize() 2019-06-26 15:46:05 +02:00
Max Kellermann
f43cafbf7d pcm/Export: eliminate the AudioFormat parameter from GetFrameSize() 2019-06-26 15:42:47 +02:00
Max Kellermann
28e07e900f pcm/Export: convert the DSD bools to an enum
These options are exclusive.
2019-06-17 22:35:00 +02:00
Max Kellermann
47bb1cd8b5 output/{alsa,osx}: use ConstBuffer::empty() 2019-06-17 22:09:47 +02:00
Max Kellermann
ccc96e25d3 output/{alsa,osx}: remove comment after PcmExport::Export()
Returning an empty buffer is a normal result now (since commit
79839db3a3), and doesn't deserve such a
big comment.
2019-06-17 22:09:06 +02:00
Max Kellermann
a139279575 Copyright year 2019 2019-06-17 11:17:30 +02:00
Max Kellermann
fd5e74dbd0 pcm/Pcm{Dop,Export}: drop "Pcm" prefix 2019-06-16 12:11:44 +02:00
Max Kellermann
973c87b351 event/Call, ...: use wait() with predicate 2019-05-07 20:01:45 +02:00
Max Kellermann
92022658f9 thread/Cond: add wait() overload which takes a unique_lock<>
Just like std::condition_variable, which however has no way to specify
the std::mutex directly.
2019-04-26 11:51:45 +02:00
Max Kellermann
b51bae5500 thread/*Cond: rename methods to match std::condition_variable 2019-04-25 19:46:43 +02: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
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