Commit graph

4534 commits

Author SHA1 Message Date
Jaroslav Kysela
70e2ed50a3 ucm: macro - fix the error message, print id
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-17 18:19:44 +02:00
Jaroslav Kysela
b67257e6fd ucm: return empty string for undefined "open" variables (arguments)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-17 14:37:41 +02:00
Jaroslav Kysela
5062565e82 ucm: allow '-' prefix to avoid errors when the variable is not defined
It may be useful to check if variable is not defined.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-17 14:36:03 +02:00
Jaroslav Kysela
11ec9e497e 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.

An example:

   "<<<v1='a b c',x=12>>>hw:1"

Variables can substituted in the configuration:

   "${var:@v1}" -> "a b c"
   "${var:@x}" -> 12

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-16 14:17:31 +02:00
Jaroslav Kysela
46e991c9ce use-case.h: add SND_USE_CASE_DEV_DIRECT define
It may be useful to define the devices without channel remapping
(e.g. ProAudio devices).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-14 16:20:33 +02:00
Jaroslav Kysela
d7d5c724ed ucm: implement MacroDefine and Macro subtree evaluation
The arguments are set as temporary variables as /MACRO_NAME/_/ARGUMENT_NAME/.

Example:

  # define new macro MyMacro with arguments ctl_name and ctl_value
  DefineMacro.MyMacro {
    BootSequence [
      cset "name='${var:MyMacro_ctl_name}' ${var:MyMacro_ctl_value}"
    ]
  }

  # instantiate macro for Speaker control (short version)
  Macro.headphone.MyMacro "ctl_name='Speaker Switch',ctl_value=off"

  # instantiate macro for Mic control (second version)
  Macro.mic.MyMacro {
	ctl_name "Mic Switch"
	ctl_value "off"
  }

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-13 17:25:29 +02:00
Jaroslav Kysela
3e5a894378 conf: fix memory leak in snd_config_substitute() for strings
When destination type is SND_CONFIG_TYPE_STRING, the old string
must be freed.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-13 16:19:50 +02:00
Jaroslav Kysela
50140120c6 ucm: local_config may be NULL (error path)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-13 16:10:56 +02:00
Jaroslav Kysela
d65b1c7b52 ucm: add ${evali:} substitution
Example:

  Define.var1 2

  LibraryConfig.test.SubstiConfig {
          a "${evali:$var1+1}"
  }

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-13 16:10:51 +02:00
Jaroslav Kysela
f1fa7ea077 control: shm - initialize write buffer
ccontrol_shm.c: In function ‘snd_ctl_shm_action’:
  control_shm.c:54:23: error: invalid initializer
     54 |         char buf[1] = 0;
        |                       ^

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-05 14:38:09 +02:00
Jaroslav Kysela
859448f010 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.

Example (aplay -l):

  card 1: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
    Subdevices: 1/1

  vs improved:

  card 1: PCH [HDA Intel PCH], device 8: HDMI 2 [Philips 272P4]
    Subdevices: 1/1

Fixes: https://github.com/alsa-project/alsa-lib/issues/209
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-05 14:31:45 +02:00
Yutao Yuan
9c0c757b85 pcm: multi: return correct hwptr and avail from snd_pcm_multi_status()
Ensure the logic of snd_pcm_multi_status() is consistent with
snd_pcm_multi_avail_update().

Fixes: https://github.com/alsa-project/alsa-lib/pull/224
Fixes: https://github.com/alsa-project/alsa-lib/issues/217
Signed-off-by: Yutao Yuan <infmagic2047reg@outlook.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-04 15:44:04 +02:00
Jaroslav Kysela
3f108fc5b8 pcm: direct - allow 'off' string for hw_ptr_alignment
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-03 19:12:03 +02:00
Jaroslav Kysela
d0ebce5928 pcm: direct - cleanups for snd_pcm_direct_reset_slave_ptr()
- improve readability
- pass slave hw_ptr as argument - improves the code flow

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-03 19:09:01 +02:00
Jaroslav Kysela
76659453ef pcm: direct - add support for channel bindings in snd_pcm_direct_query_chmaps()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-04-06 20:18:42 +02:00
Takashi Iwai
bb9f258e19 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>
2022-03-10 12:58:51 +01:00
Takashi Iwai
3577a7a26b 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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2022-03-10 12:58:51 +01:00
Takashi Iwai
b3ce9cb839 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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2022-03-10 12:58:51 +01:00
Takashi Iwai
29fbe34a0d 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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2022-03-10 12:58:51 +01:00
Alan Young
5b035bfa4a 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: 3047f8fa5a ("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>
2022-03-08 10:37:30 +01:00
Jaroslav Kysela
c41d710a69 ucm: fix the '${eval:EXPR}' substitution
There was already a variable substitution. Skip it for the eval: case.

Fixes: 7b6da9ee ("ucm: add ${eval:EXPR} substitution (Syntax 5)")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-02-22 09:51:29 +01:00
Jaroslav Kysela
3dbe072d8d conf: snd_config_merge - fix comment (overwrite / override)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 18:25:00 +01:00
Jaroslav Kysela
c687c48210 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>
2022-01-01 19:26:48 +01:00
Fabrice Fontaine
47252054b4 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.

Fixes: http://autobuild.buildroot.org/results/08d028004090b2a8292f03910cb9bf80a73ac804
Fixes: https://github.com/alsa-project/alsa-lib/pull/207
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-01 17:50:27 +01:00
Jaroslav Kysela
d6adde0e32 ucm: top-level path - set directory from symlink
It is useful to read the top-level symlink and set the configuration
directory according this symlink for the relative paths.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-13 14:40:58 +01:00
Jaroslav Kysela
1454b5f118 Release v1.2.6.1
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-09 14:17:59 +01:00
Jaroslav Kysela
4b22871ee5 conf: fix the device parsing when arguments has no defaults
The commit bf528b90 sets the value to an empty string which causes
these errors:

   pcm_hw.c: Invalid type for device
   pcm_hw.c: Invalid type for subdevice

When device arguments (@args) have no default values set,
the field must be skipped to keep the compatibility.

BugLink: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/1246
Fixes: https://github.com/alsa-project/alsa-lib/issues/199
Fixes: bf528b90 ("conf: add possibility to evaluate simple integer math expressions")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-09 10:15:47 +01:00
Jaroslav Kysela
f44c94f24c conf: accept '_' character in the variable name
Fixes: https://github.com/alsa-project/alsa-lib/issues/197
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-07 09:21:26 +01:00
Jaroslav Kysela
85b3c276d2 Release v1.2.6
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-06 11:17:27 +01:00
Jaroslav Kysela
2623e4bb76 ucm: add initial doxygen documenation
This is an attempt to explain the UCM in a more verbose way.

BugLink: https://github.com/alsa-project/alsa-ucm-conf/issues/103
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-01 10:33:44 +01:00
Jaroslav Kysela
ebb8a6c7a1 conf: introduce snd_config_load_string()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-01 10:18:58 +01:00
Jaroslav Kysela
a95942f1af conf: confeval - fix _to_integer error code
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-30 14:42:12 +01:00
Jaroslav Kysela
327bd5f28b conf: fix test/lsb/config.c
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-30 14:41:14 +01:00
Jaroslav Kysela
9b53b1f0fb conf: improve simple integer math expressions - brackets
Add brackets to the simple math expressions like:

  $[($a+($val+100))/2]

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-30 14:35:58 +01:00
Jaroslav Kysela
7b6da9ee6d ucm: add ${eval:EXPR} substitution (Syntax 5)
It is useful to do simple integer math in UCM configurations, too.
Use snd_config_evaluate_string() string for this job.

Example:

    ${eval:1+1}
    ${eval:100*$var1}
    ${eval:$[$var2+1]/5}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-30 14:22:39 +01:00
Jaroslav Kysela
bf528b9066 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.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-30 11:33:35 +01:00
Jaroslav Kysela
32d332b786 conf: add safe_strtoll_base() like safe_strtol_base()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-29 15:01:32 +01:00
Jaroslav Kysela
7ffe3d4162 ucm: fix parsing of the internal hexadecimal card identifier (2)
I forgot to change the passed variable name.

Fixes: 050f18c5 ("ucm: fix parsing of the internal hexadecimal card identifier")
Fixes: https://github.com/alsa-project/alsa-lib/issues/188
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-12 17:27:39 +01:00
Jaroslav Kysela
050f18c525 ucm: fix parsing of the internal hexadecimal card identifier
Too many code was removed.

Fixes: f547b2e3 ("conf: introduce safe_strtol_base()")
Fixes: https://github.com/alsa-project/alsa-lib/issues/188
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-12 16:00:59 +01:00
Jaroslav Kysela
ea5481296f ucm: fix DeviceModifier parser
The bellow commit caused regression for the SectionModifier parser. Revert
the single line change.

Fixes: 251bc204 ("ucm: implement RenameDevice and RemoveDevice verb management")

Fixes: https://github.com/alsa-project/alsa-lib/issues/167
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-07 18:41:43 +01:00
Jaroslav Kysela
faee7f678d pcm: softvol - mark _snd_pcm_parse_control_id as static
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-02 11:04:43 +01:00
Jaroslav Kysela
f0d540f851 pcm: partially revert "pcm: softvol - make snd_pcm_parse_control_id private"
This reverts partially commit b9a4997e92.

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>
2021-11-02 11:00:35 +01:00
Jaroslav Kysela
5fab157a59 topology: do not call strtol directly
Introduce safe_strtol_base() function and redirects all
strtol calls there. Also, improve error and value handling
in callers.

BugLink: https://github.com/alsa-project/alsa-lib/issues/187
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-02 10:45:51 +01:00
Jaroslav Kysela
f547b2e35f conf: introduce safe_strtol_base()
It is useful to parse hexadecimal strings, too.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-02 10:41:11 +01:00
Jaroslav Kysela
0e2b167e93 configure: bumb version to 1.2.6pre1 (for alsactl/alsa-utils)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 12:13:44 +02:00
Jaroslav Kysela
23198a72cd 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).

BugLink: https://github.com/alsa-project/alsa-utils/issues/111
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 11:52:08 +02:00
Jaroslav Kysela
a6a22d82a0 rawmidi: allocate the read buffer in the params call
It is better to allocate the read buffer for the framing stream
in the params setup call.

Suggested-by: David Henningsson <coding@diwic.se>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 08:40:20 +02:00
Jaroslav Kysela
392d5b06f8 rawmidi: free framing read bufffer when the framing mode becomes inactive
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 08:40:20 +02:00
Jaroslav Kysela
c932c1e7ab rawmidi: add support for SNDRV_RAWMIDI_IOCTL_USER_PVERSION
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 08:40:20 +02:00
Jaroslav Kysela
c578e80d6f rawmidi: return ENOTSUP when timestamp reads are not supported by plugins
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 08:40:20 +02:00