conf: vc4-hdmi: use a proper hdmi pcm, fix broken default pcm
Userspace expects to see a HDMI pcm, so remove the somewhat broken
front and iec958 pcms and add a proper hdmi pcm instead.
The hdmi pcm supports HD/HBR audio passthrough and relays the IEC958
status bits on to the kernel driver so it can switch to HBR audio
packets if needed. The control hook is marked optional because kernels
before 5.14 didn't expose the IEC958 controls.
The default pcm never worked as dmix doesn't support the iec958 format.
So drop dmix, only use plug and softvol, and use the hdmi pcm for
iec958 formatting.
Jaroslav Kysela [Thu, 19 May 2022 09:27:37 +0000 (11:27 +0200)]
ucm: macro - make argument names shorter
It seems that the use the macro name as the variable prefix is too large.
Use just two underscores as prefix for the macro arguments to make
macro definitions more readable.
Jaroslav Kysela [Mon, 16 May 2022 11:16:01 +0000 (13:16 +0200)]
ucm: allow passing variables through ucm open string
It is useful to pass information like application capabilities
to the UCM configuration parser. Those variables are prefixed
with '@' for the configuration files.
Jaroslav Kysela [Thu, 5 May 2022 12:28:41 +0000 (14:28 +0200)]
control: decode HDMI device name from ELD
The HDMI drivers set an uniform PCM names. Use ELD (EDID) to obtain
the HDMI device name and send this string to applications for a better
user experience.
Takashi Iwai [Thu, 10 Mar 2022 08:24:12 +0000 (09:24 +0100)]
pcm: direct: Check xrun/suspend before the slave hwptr update
The xrun/suspend may happen at any time and we should check it right
after the slave hwptr update (but before the actual sync_ptr update in
direct pcm side). Otherwise the hwptr value may be screwed and get
unexpected large read/write.
Reported-by: S.J. Wang <shengjiu.wang@nxp.com> Acked-by: Shengjiu Wang <shengjiu.wang@nxp.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai [Fri, 4 Mar 2022 09:31:08 +0000 (10:31 +0100)]
pcm: direct: Move slave PCM state checks into XRUN check helper
The check of slave PCM state is always done before the client's
recoveries count check, so let's merge them to the common helper.
Also rename the helper function to snd_pcm_direct_check_xrun() as it's
checking both slave and client states now.
Takashi Iwai [Thu, 3 Mar 2022 14:09:19 +0000 (15:09 +0100)]
pcm: direct: Improved suspend/resume support
The current resume handling in PCM direct plugins don't treat multiple
clients properly: once after the slave PCM gets resumed by one
client, the access from others at a later point is seen as already
running although the internal state isn't updated and becomes
inconsistent. This may end up a negative size, which eventually hangs
up.
This patch is an attempt to improve the handling for resume. Now the
suspended state is treated similarly like XRUN; namely, we keep the
slave PCM "recoveries" count that is modified at each time the slave
PCM XRUN happens, so that we can check the inconsistency against the
client's state. As a differentiation to XRUN, we set the highest bit
of recoveries count when the slave stream hits SUSPENDED state. This
bit is referred at comparing with clients, and the client's state is
updated to either XRUN or SUSPENDED depending on this bit.
Along with this change, the actual resume is done in
snd_pcm_direct_slave_recover(), and snd_pcm_direct_resume() rather
calls this internally.
Takashi Iwai [Thu, 3 Mar 2022 14:04:09 +0000 (15:04 +0100)]
pcm: direct: Propagate error code from snd_pcm_direct_client_chk_xrun()
Change the snd_pcm_direct_client_chk_xrun() function to return the
current XRUN state via an error code instead of the state change.
This allows the caller more straightforwardly returning its error, and
also covers the case where XRUN has been set but the function gets
called twice.
Alan Young [Wed, 23 Feb 2022 09:37:40 +0000 (09:37 +0000)]
pcm: rate: fix drain of partial period at end of buffer
In the case that:
* the buffer size is not an integer multiple of the period size, and
* drain must flush a partial period located before the end of the buffer
but without a full period available, where
* these conditions may pertain to the source or slave pcm buffer, and
* because rate conversion is always done on a full period,
it is necessary to check that both a full source period is available
before source pcm buffer wrap and a full slave period is available
before slave pcm buffer wrap in order to use the simple, single-commit
implementation in snd_pcm_rate_commit_area().
The alternative fix would be to change snd_pcm_rate_write_areas1() to
take size and slave_size parameters. This would be more disruptive to
the code base, tricky to get right, and is unnecessary given that
snd_pcm_mmap_commit() only commits the partial period of actually valid
converted samples.
Fixes: 3047f8fa5a3d ("Fix possible problems of playback drain with rate plugin") Signed-off-by: Alan Young <consult.awy@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Jaroslav Kysela [Sat, 1 Jan 2022 18:18:25 +0000 (19:18 +0100)]
conf: fix the export of safe_strto* functions from libasound
Only one library should define the safe_strto function. Export it
correctly and add _snd_ prefix to avoid possible clashes with the other
application code.
Fixes: 47252054 ("src/topology/parser.c: drop duplicate safe_strtol_base") Fixes: https://github.com/alsa-project/alsa-lib/pull/208 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/topology/parser.c: drop duplicate safe_strtol_base
The safe_strtol_base() function is defined twice since f547b2e3 ("conf: introduce safe_strtol_base()") and 5fab157a ("topology: do not call strtol directly")
resulting in the following build failure when alsa-utils is built
statically because safe_strtol_base is defined twice.
Jaroslav Kysela [Mon, 29 Nov 2021 13:57:29 +0000 (14:57 +0100)]
conf: add possibility to evaluate simple integer math expressions
It is useful to use the math expressions for the values in configuration.
This patch adds a simple expression evaluation routines (integer only).
The syntax is simplified unix shell (bash) style.
Examples:
$[1 + 1]
$[$[2 + 2] / $var1]
$[0xa0 | 0x05]
As a bonus, the variable substitutions were more abstracted.
The function snd_config_expand_custom() was introduced to be used
for example in the topology pre-precessor.
It seems that we have have some users for this very specific function.
Mark it deprecated and keep the softvol implementation separate,
so we can remove this function easily in future.
Fixes: https://github.com/alsa-project/alsa-lib/issues/186 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Jaroslav Kysela [Thu, 28 Oct 2021 09:48:54 +0000 (11:48 +0200)]
ucm: suppress the no device (no UCM card) errors on request
It seems that users are confused when the UCM configuration
is not ready for the particular hardware. Actually, we don't
allow a fine grained message classification in alsa-lib and
UCM API. Allow suppression of this specific type of messages
on the application request (typically alsactl).
Jaroslav Kysela [Wed, 22 Sep 2021 09:05:23 +0000 (11:05 +0200)]
rawmidi: rename enum snd_rawmidi_framing to snd_rawmidi_read_mode
We hide the internal data transfers using the data frames. Rename
the snd_rawmidi_framing enum to snd_rawmidi_read_mode to make
API more straight and understandable.
Jaroslav Kysela [Tue, 24 Aug 2021 09:36:30 +0000 (11:36 +0200)]
rawmidi: define more abstract API for the timestamp reads
The frame structure is a bit internal thing for the kernel
data transfer implementation. Introduce snd_rawmidi_tread()
function which is straight for the application usage and hides
the framing data transfers (kernel space API).
The current code implements the read cache and does the merging
of the frame reads with the similar timestamps (opposite
to the kernel data split for big chunks).
If the application wants to use super-duper-lighting-fast reads,
the snd_rawmidi_read() may be used, but the structure must be
defined on it's own, because this mechanism is not preferred
and unsupported.
Sava Jakovljev [Mon, 5 Jul 2021 18:28:34 +0000 (20:28 +0200)]
pcm: multi plugin - adjust appl_ptr on rewind/forward operations
When doing rewind or forward operations, application pointer needs to
be properly adjusted, in the same way when doing commit/write
operations.
Fixes: https://github.com/alsa-project/alsa-lib/pull/161 Signed-off-by: Sava Jakovljev <sava.jakovljev@teufel.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Henrik Enquist [Wed, 7 Jul 2021 19:10:16 +0000 (21:10 +0200)]
pcm: add a note about return values of snd_pcm_state()
Fixes: https://github.com/alsa-project/alsa-lib/pull/162 Signed-off-by: Henrik Enquist <henrik.enquist@gmail.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Adds a "clock type" parameter to the "rawmidi" test program, that when
used and combined with -i (and -v to be useful), activates tstamp type
framing with the specified clock type.
Signed-off-by: David Henningsson <coding@diwic.se> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Optionally, incoming rawmidi bytes can be put inside a frame of type
snd_rawmidi_framing_tstamp_t.
The main current benefit is that can enable in-kernel timestamping of
incoming bytes, and that timestamp is likely to be more precise than
what userspace can offer.
Tstamp type framing requires a kernel >= 5.14 and a buffer size that
is a multiple of sizeof(snd_rawmidi_framing_tstamp_t). It is only
available on input streams.
Signed-off-by: David Henningsson <coding@diwic.se> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Tanjeff-N. Moos [Thu, 17 Jun 2021 08:36:38 +0000 (10:36 +0200)]
control: Add documentation for snd_ctl_card_* and friends.
In this patch series, I added a description about control interface
handling and how control interfaces are identified.
In addition, I added/improved Doxygen documentation for the
snd_ctl_card_info_t type and related corresponding functions,
e.g. snd_ctl_card_info(). I also documented other card-related like
snd_card_next().
Along the way I did minor documentation improvements.
Takashi Iwai [Thu, 17 Jun 2021 08:03:17 +0000 (10:03 +0200)]
pcm: rate: Improve the support multiple formats
This patch extends the PCM rate plugin for allowing its converter
plugin to deal with multiple formats. Currently, the converter plugin
is allowed to take different formats only when convert callback is
defined. And for this way (so far only the standard linear rate
plugin does), all linear formats have to be handled, and it's
cumbersome.
OTOH, most other rate plugins are implemented with convert_s16
callback, which accepts only S16 format. This is often not ideal
because many converter engines can handle 32bit formats. Also, the
target format is often 32bit format, hence this would require
additional conversion even if the converter engine can output 32bit
natively.
In this patch, for addressing the problems above, the rate plugin API
is extended in the following way:
- The new get_supported_formats callback is added; this stores the bit
masks of the supported input and output formats, as well as the
behavior flags. Currently only linear formats are allowed.
- When the plugin accepts only the interleaved stream, set
SND_PCM_RATE_FLAG_INTERLEAVED flag bit. Otherwise the code has to
handle snd_pcm_channel_area at each call.
- When both input and output formats have to be identical, pass
SND_PCM_RATE_FLAG_SYNC_FORMATS flag bit.
- When the converter wants to process different formats, use convert
callback instead of convert_s16. You can put both in the ops for
compatibility, too.
The input and output formats are found in the info argument of init
callback.
- Now the PCM rate plugin core will skip the temporary buffer
allocation and conversions for pre- and post-process if not needed
(i.e. matching with the requested input or output format).
The rate plugin API version is bumped to 0x010003.
Introduce common helpers to allocate and release the temporary buffers
and the associated snd_pcm_channel. Now two allocated objects are
used instead of one malloc to be split.
Also, change the snd_pcm_channel set up to be in interleaved mode.
This will be necessary in the following change in the rate plugin.
Jaroslav Kysela [Tue, 15 Jun 2021 21:21:42 +0000 (23:21 +0200)]
control: empty - fix the static build
Reported-by: Jan Palus <atler@pld-linux.org> Fixes: https://github.com/alsa-project/alsa-lib/issues/157 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Chih-Wei Huang [Mon, 14 Jun 2021 04:24:10 +0000 (12:24 +0800)]
configure: check if eaccess() is available
To fix the build error on Android:
src/ucm/parser.c:2521:7: error: implicit declaration of function 'eaccess' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (eaccess(filename, R_OK))
^
src/ucm/parser.c:2521:7: note: did you mean 'access'?
Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Chih-Wei Huang [Mon, 14 Jun 2021 04:21:35 +0000 (12:21 +0800)]
ucm: include sys/wait.h to fix build on Android
src/ucm/main.c:788:8: error: implicit declaration of function 'WIFSIGNALED' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (WIFSIGNALED(err)) {
^
src/ucm/main.c:790:10: error: implicit declaration of function 'WIFEXITED' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
} if (WIFEXITED(err)) {
^
src/ucm/main.c:791:34: error: implicit declaration of function 'WEXITSTATUS' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (ignore_error == false && WEXITSTATUS(err) != 0) {
Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Andreas Müller [Thu, 3 Jun 2021 10:29:03 +0000 (12:29 +0200)]
ucm_exec.c: Include limits.h explicitly to fix build on musl
Fixes:
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c: In function 'find_exec':
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c:43:18: error: 'PATH_MAX' undeclared (first use in this function)
| 43 | char bin[PATH_MAX];
| | ^~~~~~~~
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c:43:18: note: each undeclared identifier is reported only once for each function it appears in
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c: In function 'uc_mgr_exec':
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c:177:18: error: 'PATH_MAX' undeclared (first use in this function)
| 177 | char bin[PATH_MAX];
| | ^~~~~~~~
Fixes: https://github.com/alsa-project/alsa-lib/pull/145 Signed-off-by: Andreas Müller <schnitzeltony@gmail.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>