Commit graph

47 commits

Author SHA1 Message Date
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
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
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
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
4a52ae4c32 ucm: fix the parsing of the hexadecimal prefix
The safe_strtol() function use strtol() which expects
to have the '0x' prefix for the hexadecimal number (when
base argument is zero).

BugLink: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1553
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-31 09:42:02 +02:00
Jaroslav Kysela
7d40a76ef5 ucm: avoid zero card instance number
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-31 09:25:12 +02:00
Jaroslav Kysela
5e7c507152 ucm: add cfg-save command
Allow to save whole (or partial) local UCM alsa library configuration
to a file.

Syntax (saves key1.key2 sub-tree):

	Sequence [
		cfg-save "/tmp/my-file.conf:key1.key2"
	]

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-17 16:49:46 +02:00
Jaroslav Kysela
590df3a5b1 ucm: add exec sequence command
This change renames the original exec command to shell which
is more appropriate. Implement a light version of the exec
command which calls directly the specified executable without
the shell interaction (man 3 system).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-12 08:32:45 +02:00
Jaroslav Kysela
6ddba54a07 ucm: fix the local ucm control device name caching
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-23 21:19:34 +02:00
Jaroslav Kysela
8f5779eb3f ucm: add LibraryConfig support
This commit allows to define private alsa-lib's configuration. When
the configuration is present, the device values ("PlaybackCTL",
"CaptureCTL", "PlaybackMixer", "CaptureMixer", "CapturePCM")
are prefixed with '_ucmHEXA.' string where HEXA is replaced by the
unique hexadecimal number identifying the opened ucm manager handle.

    Syntax 4

    LibraryConfig.a_label.SubstiConfig {
            # substituted library configuration like:
            usr_share_dir "${ConfLibDir}"
    }

    LibraryConfig.b_label.Config {
            # non-substituted library configuration like:
            usr_share_dir "/usr/share/alsa"
    }

    The File counterparts:

    LibraryConfig.c_label.SubstiFile "/some/path"
    LibraryConfig.d_label.File "/some/path"

Note that for files the contents is substituted on the request,
but the file name is always substituted (useful for ${ConfDir} etc.).

The private configuration is not saved or preserved. It's life time
belongs to the opened ucm manager handle.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 17:14:28 +02:00
Jaroslav Kysela
3cfbacdc34 ucm: add ctl-remove sequence command to delete controls from UCM
Syntax:

   ctl-remove "name='ABCD'"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-29 11:31:08 +02:00
Jaroslav Kysela
02423dc970 ucm: add cset-new sequence command to create new controls from UCM
This command create a new control using ID, description and value.

Syntax:

    cset-new "name='ABCD',index=2 type=boolean,count=2 on,on"
    cset-new "name='Enum' type=enum,labels='L1;L2;L3' 'L2'"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-29 11:00:25 +02:00
Jaroslav Kysela
0afa61e8f0 ucm: rename sysset to sysw
Fixes: 1c6fb202 ("ucm: implement sysset sequence command")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-23 11:40:30 +01:00
Jaroslav Kysela
1c6fb20232 ucm: implement sysset sequence command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:26:07 +01:00
Jaroslav Kysela
9c194a0ba7 ucm: add _fboot / FixedBootSequence
Actually, the BootSequence is executed only when the driver controls
(identifiers or value types) are changed. It may be handy to have
also a sequence which is executed at _each_ boot without any condition.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:25:52 +01:00
Jaroslav Kysela
296b067fc7 ucm: add ${find-card} and ${find-device} substitutions
It may be useful to find a correct card or device through
control API information fields.

Increase the syntax version to 4.

Examples:

  ${find-card:field=name,regex='HDA Intel'}
  ${find-device:type=pcm,field=id,regex='HDMI 1$'}
  ${find-device:ctl=hw:acp,type=pcm,field=id,regex=DMIC}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-02-03 11:42:56 +01:00
Jaroslav Kysela
2b217b7010 ucm: rename once_list to boot_list
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:47:11 +02:00
Jaroslav Kysela
6fad36dd38 ucm: fix the wrong return value in uc_mgr_open_ctl()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-08 09:57:35 +02:00
Jaroslav Kysela
eee879d381 ucm: implement CardIdByName substitution
The syntax is ${CardIdByName:CARDNAME[#INDEX]}.

The CARDNAME is the ALSA's soundcard name (short form).
The INDEX is the instance (0 = first, 1 = second etc.).

Example: ${CardIdByName:HDA Intel PCH}
(which is identical to ${CardIdByName:HDA Intel PCH#0})

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-03 17:17:11 +02:00
Jaroslav Kysela
ed4567d1c9 ucm: configuration - allow to define the configuration variables
It may be useful for the library files to use the runtime configuration
variables.

Example:

 Define.Var1 "hw:${CardId},2"
 Value.PlaybackPCM "${var:Var1}"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
3edfebc522 ucm: configuration - implement in-place Include
An example:

	Include {
		File "Inc.conf"
		Before.SectionDevice "Mic"
	}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
e0da1d2a2a ucm: parse SectionOnce section in the master UCM configuration file
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 16:04:38 +02:00
Jaroslav Kysela
c9605484d1 ucm: fix the device remove operation
- allow to remove device only from conflicting lists
- unify the error codes when the device is not found (ENODEV)

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-04-06 13:25:46 +02:00
Jaroslav Kysela
fdf96312fa ucm: fill missing device entries (conflicting / supported)
It is not necessary to maintain this information in sync in the configuration
files. Fill the missing entries to the complementary devices.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-02-07 16:20:56 +01:00
Jaroslav Kysela
251bc204a1 ucm: implement RenameDevice and RemoveDevice verb management
With the conditionals, it may be useful to define the devices
in the included configuration files. To satisfy the specification
requirements (device naming) those device names might require
to be renamed or deleted wrong references from the conflicting
or supported lists.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-02-07 16:20:49 +01:00
Jaroslav Kysela
fe6425af75 ucm: split conf_file_name and conf_dir_name
With ucm2, the file name might differ from the directory
name. Also, allocate those fields.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-01-15 10:40:35 +01:00
Jaroslav Kysela
8a36e38dc4 ucm: add If condition block
The syntax is simple:

If./any-if-identificator/ {
  Condition {
    Type /type_here/
    /optional defines/
  }
  True {
    /block used when condition is evaluated as true/
  }
  False {
    /block used when condition is evaluated as false/
  }
}

The Type "ControlExists" is implemented:

Condition {
  Type ControlExists
  Device "hw:${CardId}"
  Control "iface=CARD,name='Headphone Jack'"
}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-14 15:00:37 +01:00
Jaroslav Kysela
d8dfe4dac7 ucm: save the whole ctl info to the ctl_list structure
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-10 13:12:21 +01:00
Jaroslav Kysela
40aef87f1e ucm: fix memory leaks for cdev, bin-file and tlv elements
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-10 13:12:21 +01:00
Jaroslav Kysela
32ff0ba7a3 ucm: add support for multiple control devices, more aggresive caching
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-10 13:11:35 +01:00
Jaroslav Kysela
aba2260ae7 ucm: switch to ucm2 directory and v2 format, keep backward compatibility
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-10 13:10:33 +01:00
Jaroslav Kysela
f600310954 conf: improve the include paths code
- various cleanups (more straight code and allocations)
- do not add the base config path /usr/share/alsa to the
  explicit include list of directories
  (it's not wanted for ucm configs)

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-10 13:05:53 +01:00
Jaroslav Kysela
5905af1996 ucm: another coverity fix in uc_mgr_config_load() 2019-05-27 20:10:52 +02:00
Jaroslav Kysela
ed156a2186 ucm: coverity fixes
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-05-24 21:25:50 +02:00
Jaroslav Kysela
1e5ecbc806 conf: rename snd_conf_load1() to _snd_config_load_with_include()
Always free the include path which must be mallocated by the caller.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-01-07 13:15:34 +01:00
Takashi Iwai
c9fcf98369 ucm: Set default include path
Many UCM profiles include the UCM profile components under ucm/*
subdirectories and thusly put <searchdir:ucm> at each place.  This is
rather cumbersome.

This patch makes the UCM parser to set the default include path, so
that each profile no longer needs to set searchdir.  All the
<searchdir:ucm> lines currently found in the profiles are removed
gracefully, too.

For the needed implementation, a new helper,
_snd_config_load_with_include() is introduced.  It's not exported,
only for the use inside alsa-lib.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-11-29 09:40:10 +01:00
Jaroslav Kysela
5b9041bced Change FSF address (Franklin Street)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2017-11-14 14:29:26 +01:00
Mengdong Lin
14c930d0c9 ucm: Parse sequence of component devices
A machine device's sequence can enable or disable a component device by
keyword 'enadev' and 'disdev' followed the name of the component device.

UCM sequence parser will find the component device and mark if its enable
or disable sequence is needed by the parent, the machine device.

New element type and struct are defined for the sequence of a component
device. Component devices will be removed from the machine device list
'device_list' of a verb, since we don't want to expose them to audio
servers with original API to list devices for backward compatibility.
A new list 'cmpt_device_list' is used for the component devices of a verb.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-12-02 20:29:22 +01:00
Stephen Warren
fc038149c5 UCM: Implement ConflictingDevices, add device list to devices
Wherever SupportedDevice can appear, also allow ConflictingDevice. Only
one or the other (or neither) may be specified. When neither is
specified, allow anything. Sometimes, listing ConflictingDevices may
result in a shorter list than explicitly listing all SupportedDevices.

Add support for SupportedDevice and ConflictingDevice to SectionDevice.
This allows representing devices which are mutually exclusive, e.g. due
to a mux that switches between capturing from two different microphones,
without the possibility of mixing.

Enhance is_modifier_supported to allow ignoring SupportedDevice and
ConflictingDevice. This is useful when querying values from a
SectionModifier; there's no reason we shouldn't be able to query values
just because the current configuration would prevent enabling that
device. The new is_device_supported is implemented similarly.

Enhance switch_device to remove the old device from the current device
list before querying for the new device, and add it back immediately
afterwards. This allows the query for the new device to ignore any
conflicts caused solely by the old device.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-06-08 18:20:26 +02:00
Jaroslav Kysela
e419f63960 UCM: Fix LGPL licence ("how to receive" part referred GPL instead LGPL)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2011-03-28 11:06:33 +02:00
Jaroslav Kysela
7d3de218ce ucm: initial implementation for cdev/cset
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-11-29 17:33:27 +01:00
Jaroslav Kysela
d8b7816196 ucm: add ValueDefaults section to the master file
- the get_value() function is recoded (tries to find the value in
  parent's list)

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-11-29 15:41:34 +01:00
Jaroslav Kysela
e4083a1182 ucm: debug parser
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-10-26 14:26:46 +02:00
Jaroslav Kysela
e820866637 ucm: implemented card list feature
- also added some test files to test/ucm tree

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-10-13 11:48:52 +02:00
Jaroslav Kysela
404cd090b2 ucm: Introduce "Value {}" section, more implementation work
- new "Value {}" section is introduced for read-only values
  describing the PCM and control/mixer IDs (or any other
  things)
- more complete implementation for API functions

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-09-22 14:31:15 +02:00
Jaroslav Kysela
1c79fad969 ucm: Moved ucm to src/ucm subdirectory
- separate code to more files
- use standard lists to represent structures
- use alsa-lib configuration parser

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-09-15 08:09:31 +02:00