ALSA project - the C library reference

Macros | Typedefs | Functions
Use Case Interface

## Macros
#define | SND_USE_CASE_VERB_INACTIVE "Inactive"
#define | SND_USE_CASE_VERB_HIFI "HiFi"
#define | SND_USE_CASE_VERB_HIFI_LOW_POWER "HiFi Low Power"
#define | SND_USE_CASE_VERB_VOICE "Voice"
#define | SND_USE_CASE_VERB_VOICE_LOW_POWER "Voice Low Power"
#define | SND_USE_CASE_VERB_VOICECALL "Voice Call"
#define | SND_USE_CASE_VERB_IP_VOICECALL "Voice Call IP"
#define | SND_USE_CASE_VERB_ANALOG_RADIO "FM Analog Radio"
#define | SND_USE_CASE_VERB_DIGITAL_RADIO "FM Digital Radio"
#define | SND_USE_CASE_DEV_NONE "None"
#define | SND_USE_CASE_DEV_SPEAKER "Speaker"
#define | SND_USE_CASE_DEV_LINE "Line"
#define | SND_USE_CASE_DEV_MIC "Mic"
#define | SND_USE_CASE_DEV_HEADPHONES "Headphones"
#define | SND_USE_CASE_DEV_HEADSET "Headset"
#define | SND_USE_CASE_DEV_HANDSET "Handset"
#define | SND_USE_CASE_DEV_BLUETOOTH "Bluetooth"
#define | SND_USE_CASE_DEV_EARPIECE "Earpiece"
#define | SND_USE_CASE_DEV_SPDIF "SPDIF"
#define | SND_USE_CASE_DEV_HDMI "HDMI"
#define | SND_USE_CASE_DEV_USB "USB"
#define | SND_USE_CASE_DEV_DIRECT "Direct"
#define | SND_USE_CASE_MOD_CAPTURE_VOICE "Capture Voice"
#define | SND_USE_CASE_MOD_CAPTURE_MUSIC "Capture Music"
#define | SND_USE_CASE_MOD_PLAY_MUSIC "Play Music"
#define | SND_USE_CASE_MOD_PLAY_VOICE "Play Voice"
#define | SND_USE_CASE_MOD_PLAY_TONE "Play Tone"
#define | SND_USE_CASE_MOD_ECHO_REF "Echo Reference"
#define | SND_USE_CASE_TQ_MUSIC "Music"
#define | SND_USE_CASE_TQ_VOICE "Voice"
#define | SND_USE_CASE_TQ_TONES "Tones"

## Typedefs
typedef struct snd_use_case_mgr | snd_use_case_mgr_t

## Functions
char * | snd_use_case_identifier (const char *fmt,...)
| Create an identifier. More...
int | snd_use_case_free_list (const char *list[], int items)
| Free a string list. More...
int | snd_use_case_get_list (snd_use_case_mgr_t *uc_mgr, const char *identifier, const char **list[])
| Obtain a list of entries. More...
int | snd_use_case_get (snd_use_case_mgr_t *uc_mgr, const char *identifier, const char **value)
| Get current - string. More...
int | snd_use_case_geti (snd_use_case_mgr_t *uc_mgr, const char *identifier, long *value)
| Get current - integer. More...
int | snd_use_case_set (snd_use_case_mgr_t *uc_mgr, const char *identifier, const char *value)
| Set new. More...
int | snd_use_case_mgr_open (snd_use_case_mgr_t **uc_mgr, const char *card_name)
| Open and initialise use case core for sound card. More...
int | snd_use_case_mgr_reload (snd_use_case_mgr_t *uc_mgr)
| Reload and re-parse use case configuration files for sound card. More...
int | snd_use_case_mgr_close (snd_use_case_mgr_t *uc_mgr)
| Close use case manager. More...
int | snd_use_case_mgr_reset (snd_use_case_mgr_t *uc_mgr)
| Reset use case manager verb, device, modifier to deafult settings. More...
int | snd_use_case_parse_ctl_elem_id (snd_ctl_elem_id_t *dst, const char *ucm_id, const char *value)
| Parse control element identifier. More...
int | snd_use_case_parse_selem_id (snd_mixer_selem_id_t *dst, const char *ucm_id, const char *value)
| Parse mixer element identifier. More...

## Detailed Description

The ALSA Use Case manager interface. See ALSA Use Case Interface page for more details.

### ALSA Use Case Interface

The use case manager works by configuring the sound card ALSA kcontrols to change the hardware digital and analog audio routing to match the requested device use case. The use case manager kcontrol configurations are stored in easy to modify text files.An audio use case can be defined by a verb and device parameter. The verb describes the use case action i.e. a phone call, listening to music, recording a conversation etc. The device describes the physical audio capture and playback hardware i.e. headphones, phone handset, bluetooth headset, etc.It's intended clients will mostly only need to set the use case verb and device for each system use case change (as the verb and device parameters cover most audio use cases).However there are times when a use case has to be modified at runtime. e.g.

- Incoming phone call when the device is playing music
- Recording sections of a phone call
- Playing tones during a call.

In order to allow asynchronous runtime use case adaptations, we have a third optional modifier parameter that can be used to further configure the use case during live audio runtime.This interface allows clients to :-

- Query the supported use case verbs, devices and modifiers for the machine.
- Set and Get use case verbs, devices and modifiers for the machine.
- Get the ALSA PCM playback and capture device PCMs for use case verb, use case device and modifier.
- Get the TQ parameter for each use case verb, use case device and modifier.
- Get the ALSA master playback and capture volume/switch kcontrols or mixer elements for each use case.

## Macro Definition Documentation

## ◆ SND_USE_CASE_DEV_BLUETOOTH

#define SND_USE_CASE_DEV_BLUETOOTH "Bluetooth"

Bluetooth Device

## ◆ SND_USE_CASE_DEV_DIRECT

#define SND_USE_CASE_DEV_DIRECT "Direct"

Direct Device (no channel remapping), (e.g. ProAudio usage)

## ◆ SND_USE_CASE_DEV_EARPIECE

#define SND_USE_CASE_DEV_EARPIECE "Earpiece"

Earpiece Device

## ◆ SND_USE_CASE_DEV_HANDSET

#define SND_USE_CASE_DEV_HANDSET "Handset"

Handset Device

## ◆ SND_USE_CASE_DEV_HDMI

#define SND_USE_CASE_DEV_HDMI "HDMI"

HDMI Device

## ◆ SND_USE_CASE_DEV_HEADPHONES

#define SND_USE_CASE_DEV_HEADPHONES "Headphones"

Headphones Device

## ◆ SND_USE_CASE_DEV_HEADSET

#define SND_USE_CASE_DEV_HEADSET "Headset"

Headset Device

## ◆ SND_USE_CASE_DEV_LINE

#define SND_USE_CASE_DEV_LINE "Line"

Line Device

## ◆ SND_USE_CASE_DEV_MIC

#define SND_USE_CASE_DEV_MIC "Mic"

Microphone Device

## ◆ SND_USE_CASE_DEV_NONE

#define SND_USE_CASE_DEV_NONE "None"

None Device

## ◆ SND_USE_CASE_DEV_SPDIF

#define SND_USE_CASE_DEV_SPDIF "SPDIF"

SPDIF Device

## ◆ SND_USE_CASE_DEV_SPEAKER

#define SND_USE_CASE_DEV_SPEAKER "Speaker"

Speaker Device

## ◆ SND_USE_CASE_DEV_USB

#define SND_USE_CASE_DEV_USB "USB"

USB Device (multifunctional)

## ◆ SND_USE_CASE_MOD_CAPTURE_MUSIC

#define SND_USE_CASE_MOD_CAPTURE_MUSIC "Capture Music"

Capture Music Modifier

## ◆ SND_USE_CASE_MOD_CAPTURE_VOICE

#define SND_USE_CASE_MOD_CAPTURE_VOICE "Capture Voice"

Capture Voice Modifier

## ◆ SND_USE_CASE_MOD_ECHO_REF

#define SND_USE_CASE_MOD_ECHO_REF "Echo Reference"

Echo Reference Modifier

## ◆ SND_USE_CASE_MOD_PLAY_MUSIC

#define SND_USE_CASE_MOD_PLAY_MUSIC "Play Music"

Play Music Modifier

## ◆ SND_USE_CASE_MOD_PLAY_TONE

#define SND_USE_CASE_MOD_PLAY_TONE "Play Tone"

Play Tone Modifier

## ◆ SND_USE_CASE_MOD_PLAY_VOICE

#define SND_USE_CASE_MOD_PLAY_VOICE "Play Voice"

Play Voice Modifier

## ◆ SND_USE_CASE_TQ_MUSIC

#define SND_USE_CASE_TQ_MUSIC "Music"

TQ - Tone Quality

The interface allows clients to determine the audio TQ required for each use case verb and modifier. It's intended as an optional hint to the audio driver in order to lower power consumption. Music Tone Quality

## ◆ SND_USE_CASE_TQ_TONES

#define SND_USE_CASE_TQ_TONES "Tones"

Tones Tone Quality

## ◆ SND_USE_CASE_TQ_VOICE

#define SND_USE_CASE_TQ_VOICE "Voice"

Voice Tone Quality

## ◆ SND_USE_CASE_VERB_ANALOG_RADIO

#define SND_USE_CASE_VERB_ANALOG_RADIO "FM Analog Radio"

FM Analog Radio Verb

## ◆ SND_USE_CASE_VERB_DIGITAL_RADIO

#define SND_USE_CASE_VERB_DIGITAL_RADIO "FM Digital Radio"

FM Digital Radio Verb

## ◆ SND_USE_CASE_VERB_HIFI

#define SND_USE_CASE_VERB_HIFI "HiFi"

HiFi Verb

## ◆ SND_USE_CASE_VERB_HIFI_LOW_POWER

#define SND_USE_CASE_VERB_HIFI_LOW_POWER "HiFi Low Power"

HiFi Low Power Verb

## ◆ SND_USE_CASE_VERB_INACTIVE

#define SND_USE_CASE_VERB_INACTIVE "Inactive"

Inactive Verb

## ◆ SND_USE_CASE_VERB_IP_VOICECALL

#define SND_USE_CASE_VERB_IP_VOICECALL "Voice Call IP"

Voice Call IP Verb

## ◆ SND_USE_CASE_VERB_VOICE

#define SND_USE_CASE_VERB_VOICE "Voice"

Voice Verb

## ◆ SND_USE_CASE_VERB_VOICE_LOW_POWER

#define SND_USE_CASE_VERB_VOICE_LOW_POWER "Voice Low Power"

Voice Low Power Verb

## ◆ SND_USE_CASE_VERB_VOICECALL

#define SND_USE_CASE_VERB_VOICECALL "Voice Call"

Voice Call Verb

## Typedef Documentation

## ◆ snd_use_case_mgr_t

typedef struct snd_use_case_mgr snd_use_case_mgr_t

use case container

## Function Documentation

## ◆ snd_use_case_free_list()

int snd_use_case_free_list | ( | const char * | list[],
|  | int | items
| ) |  |

Free a string list.

Parameters

  list | The string list to free
  items | Count of strings

Returns
  Zero if success, otherwise a negative error code

## ◆ snd_use_case_get()

int snd_use_case_get | ( | snd_use_case_mgr_t * | uc_mgr,
|  | const char * | identifier,
|  | const char ** | value
| ) |  |

Get current - string.

Parameters

  uc_mgr | Use case manager
  identifier |
  value | Value pointer

Returns
  Zero if success, otherwise a negative error code

Note: The returned string is dynamically allocated, use free() to deallocate this string. (Yes, the value parameter shouldn't be marked as "const", but it's too late to fix it, sorry about that.)

Known identifiers:

- NULL - return current card
- _verb - return current verb
- _file - return configuration file loaded for current card
- _alibcfg - return private alsa-lib's configuration for current card
- _alibpref - return private alsa-lib's configuration device prefix for current card
- [=]{NAME}[/[{modifier}|{/device}][/{verb}]]
  - value identifier {NAME}
  - Search starts at given modifier or device if any, else at a verb
  - Search starts at given verb if any, else current verb
  - Searches modifier/device, then verb, then defaults
  - Specify a leading "=" to search only the exact device/modifier/verb specified, and not search through each object in turn.
  - Examples:
    - "PlaybackPCM/Play Music"
    - "CapturePCM/SPDIF"
    - From ValueDefaults only: "=Variable"
    - From current active verb: "=Variable//"
    - From verb "Verb": "=Variable//Verb"
    - From "Modifier" in current active verb: "=Variable/Modifier/"
    - From "Modifier" in "Verb": "=Variable/Modifier/Verb"

Recommended names for values:

- Linked
  - value "True" or "1" (case insensitive)
  - this is a linked UCM card
  - don't use this UCM card, because the other UCM card refers devices
  - valid only in the ValueDefaults section (query '=Linked')
- TQ
  - Tone Quality
- Priority
  - priority value (1-10000), higher value means higher priority
  - valid only for verbs
  - for devices - PlaybackPriority and CapturePriority
- PlaybackPCM
  - full PCM playback device name
- PlaybackPCMIsDummy
  - Valid values: "yes" and "no". If set to "yes", the PCM named by the PlaybackPCM value is a dummy device, meaning that opening it enables an audio path in the hardware, but writing to the PCM device has no effect.
- CapturePCM
  - full PCM capture device name
- CapturePCMIsDummy
  - Valid values: "yes" and "no". If set to "yes", the PCM named by the CapturePCM value is a dummy device, meaning that opening it enables an audio path in the hardware, but reading from the PCM device has no effect.
- PlaybackRate
  - playback device sample rate
- PlaybackChannels
  - playback device channel count
- PlaybackChannel#
  - describe index of the logical channel in the PCM stream
  - e.g. "PlaybackChannel0 2" - logical channel 0 is third channel in the PCM stream
- PlaybackChannelPos#
  - describe sound position of the logical channel (ALSA chmap names)
  - e.g. "PlaybackChannel0 FR" - logical channel 0 is at front left
- PlaybackCTL
  - playback control device name
- PlaybackVolume
  - playback control volume identifier string

can be parsed using snd_use_case_parse_ctl_elem_id()

- PlaybackSwitch
  - playback control switch identifier string

can be parsed using snd_use_case_parse_ctl_elem_id()

- PlaybackPriority
  - priority value (1-10000), higher value means higher priority
- CaptureRate
  - capture device sample rate
- CaptureChannels
  - capture device channel count
- CaptureChannel#
  - describe index of the logical channel in the PCM stream
  - e.g. "CaptureChannel0 2" - logical channel 0 is third channel in the PCM stream
- CaptureChannelPos#
  - describe sound position of the logical channel (ALSA chmap names)
  - e.g. "CaptureChannel0 FR" - logical channel 0 is at front left
- CaptureCTL
  - capture control device name
- CaptureVolume
  - capture control volume identifier string

can be parsed using snd_use_case_parse_ctl_elem_id()

- CaptureSwitch
  - capture control switch identifier string

can be parsed using snd_use_case_parse_ctl_elem_id()

- CapturePriority
  - priority value (1-10000), higher value means higher priority
- PlaybackMixer
  - name of playback mixer
- PlaybackMixerElem
  - mixer element playback identifier

can be parsed using snd_use_case_parse_selem_id()

- PlaybackMasterElem
  - mixer element playback identifier for the master control

can be parsed using snd_use_case_parse_selem_id()

- PlaybackMasterType
  - type of the master volume control
  - Valid values: "soft" (software attenuation)
- CaptureMixer
  - name of capture mixer
- CaptureMixerElem
  - mixer element capture identifier

can be parsed using snd_use_case_parse_selem_id()

- CaptureMasterElem
  - mixer element playback identifier for the master control

can be parsed using snd_use_case_parse_selem_id()

- CaptureMasterType
  - type of the master volume control
  - Valid values: "soft" (software attenuation)
- EDIDFile
  - Path to EDID file for HDMI devices
- JackCTL
  - jack control device name
- JackControl
  - jack control identificator
  - can be parsed using snd_use_case_parse_ctl_elem_id()
  - UCM configuration files should contain both JackControl and JackDev when possible, because applications are likely to support only one or the other
- JackDev
  - the input device id of the jack (if the full input device path is /dev/input/by-id/foo, the JackDev value should be "foo")
  - UCM configuration files should contain both JackControl and JackDev when possible, because applications are likely to support only one or the other
- JackHWMute If this value is set, it indicates that when the jack is plugged in, the hardware automatically mutes some other device(s). The value is a space-separated list of device names. If the device name contains space, it must be enclosed to ' or ", e.g.: JackHWMute "'Dock Headphone' Headphone" Note that JackHWMute should be used only when the hardware enforces the automatic muting. If the hardware doesn't enforce any muting, it may still be tempting to set JackHWMute to trick upper software layers to e.g. automatically mute speakers when headphones are plugged in, but that's application policy configuration that doesn't belong to UCM configuration files. - MinBufferLevel - This is used on platform where reported buffer level is not accurate. E.g. "512", which holds 512 samples in device buffer. Note: this will increase latency.

Parameters

  uc_mgr | Use case manager
  identifier |
  value | Value pointer

Returns
  Zero if success, otherwise a negative error code

Note: String is dynamically allocated, use free() to deallocate this string.

## ◆ snd_use_case_get_list()

int snd_use_case_get_list | ( | snd_use_case_mgr_t * | uc_mgr,
|  | const char * | identifier,
|  | const char ** | list[]
| ) |  |

Obtain a list of entries.

Parameters

  uc_mgr | Use case manager (may be NULL - card list)
  identifier | (may be NULL - card list)
  list | Returned allocated list

Returns
  Number of list entries if success, otherwise a negative error code

Defined identifiers:

- NULL - get card list (in pair cardname+comment)
- _verbs - get verb list (in pair verb+comment)
- _devices[/{verb}] - get list of supported devices (in pair device+comment)
- _modifiers[/{verb}] - get list of supported modifiers (in pair modifier+comment)
- TQ[/{verb}] - get list of TQ identifiers
- _enadevs - get list of enabled devices
- _enamods - get list of enabled modifiers
- _identifiers/{modifier}|{device}[/{verb}] - list of value identifiers
- _supporteddevs/{modifier}|{device}[/{verb}] - list of supported devices
- _conflictingdevs/{modifier}|{device}[/{verb}] - list of conflicting devices

Note that at most one of the supported/conflicting devs lists has any entries, and when neither is present, all devices are supported.

Parameters

  uc_mgr | Use case manager (may be NULL - card list)
  identifier | (may be NULL - card list)
  list | Returned allocated list

Returns
  Number of list entries if success, otherwise a negative error code

## ◆ snd_use_case_geti()

int snd_use_case_geti | ( | snd_use_case_mgr_t * | uc_mgr,
|  | const char * | identifier,
|  | long * | value
| ) |  |

Get current - integer.

Parameters

  uc_mgr | Use case manager
  identifier |
  value | result

Returns
  Zero if success, otherwise a negative error code

Known identifiers:

- _devstatus/{device} - return status for given device
- _modstatus/{modifier} - return status for given modifier

Parameters

  uc_mgr | Use case manager
  identifier |

Returns
  Value if success, otherwise a negative error code

## ◆ snd_use_case_identifier()

char * snd_use_case_identifier | ( | const char * | fmt,
|  |  | ...
| ) |  |

Create an identifier.

Parameters

  fmt | Format (sprintf like)
  ... | Optional arguments for sprintf like format

Returns
  Allocated string identifier or NULL on error

## ◆ snd_use_case_mgr_close()

int snd_use_case_mgr_close | ( | snd_use_case_mgr_t * | uc_mgr | ) |

Close use case manager.

Parameters

  uc_mgr | Use case manager

Returns
  zero if success, otherwise a negative error code

Parameters

  uc_mgr | Use case manager

Returns
  zero on success, otherwise a negative error code

## ◆ snd_use_case_mgr_open()

int snd_use_case_mgr_open | ( | snd_use_case_mgr_t ** | uc_mgr,
|  | const char * | card_name
| ) |  |

Open and initialise use case core for sound card.

Parameters

  uc_mgr | Returned use case manager pointer
  card_name | Sound card name.

Returns
  zero if success, otherwise a negative error code

By default only first card is used when the driver card name or long name is passed in the card_name argument.

The "strict:" prefix in the card_name defines that there is no driver name / long name matching. The straight configuration is used.

The "hw:" prefix in the card_name will load the configuration for the ALSA card specified by the card index (value) or the card string identificator.

The sound card might be also composed from several physical sound cards (for the default and strict card_name). The application cannot expect that the device names will refer only one ALSA sound card in this case.

Open and initialise use case core for sound card.

Parameters

  uc_mgr | Returned use case manager pointer
  card_name | name of card to open

Returns
  zero on success, otherwise a negative error code

## ◆ snd_use_case_mgr_reload()

int snd_use_case_mgr_reload | ( | snd_use_case_mgr_t * | uc_mgr | ) |

Reload and re-parse use case configuration files for sound card.

Parameters

  uc_mgr | Use case manager

Returns
  zero if success, otherwise a negative error code

Reload and re-parse use case configuration files for sound card.

Parameters

  uc_mgr | Use case manager

Returns
  zero on success, otherwise a negative error code

## ◆ snd_use_case_mgr_reset()

int snd_use_case_mgr_reset | ( | snd_use_case_mgr_t * | uc_mgr | ) |

Reset use case manager verb, device, modifier to deafult settings.

Parameters

  uc_mgr | Use case manager

Returns
  zero if success, otherwise a negative error code

Reset use case manager verb, device, modifier to deafult settings.

Parameters

  uc_mgr | Use case manager

Returns
  zero on success, otherwise a negative error code

## ◆ snd_use_case_parse_ctl_elem_id()

int snd_use_case_parse_ctl_elem_id | ( | snd_ctl_elem_id_t * | dst,
|  | const char * | ucm_id,
|  | const char * | value
| ) |  |

Parse control element identifier.

Parameters

  elem_id | Element identifier
  ucm_id | Use case identifier
  value | String value to be parsed

Returns
  Zero if success, otherwise a negative error code

## ◆ snd_use_case_parse_selem_id()

int snd_use_case_parse_selem_id | ( | snd_mixer_selem_id_t * | dst,
|  | const char * | ucm_id,
|  | const char * | value
| ) |  |

Parse mixer element identifier.

Parameters

  dst | Simple mixer element identifier
  ucm_id | Use case identifier
  value | String value to be parsed

Returns
  Zero if success, otherwise a negative error code

## ◆ snd_use_case_set()

int snd_use_case_set | ( | snd_use_case_mgr_t * | uc_mgr,
|  | const char * | identifier,
|  | const char * | value
| ) |  |

Set new.

Parameters

  uc_mgr | Use case manager
  identifier |
  value | Value

Returns
  Zero if success, otherwise a negative error code

Known identifiers:

- _fboot - execute the fixed boot sequence (value = NULL)
- _boot - execute the boot sequence (value = NULL)
  - only when driver controls identifiers are changed (otherwise the old control values are restored)
- _defaults - execute the 'defaults' sequence (value = NULL)
- _verb - set current verb = value
- _enadev - enable given device = value
- _disdev - disable given device = value
- _swdev/{old_device} - new_device = value
  - disable old_device and then enable new_device
  - if old_device is not enabled just return
  - check transmit sequence firstly
- _enamod - enable given modifier = value
- _dismod - disable given modifier = value
- _swmod/{old_modifier} - new_modifier = value
  - disable old_modifier and then enable new_modifier
  - if old_modifier is not enabled just return
  - check transmit sequence firstly

Parameters

  uc_mgr | Use case manager
  identifier |
  value | Value

Returns
  Zero if success, otherwise a negative error code