2 * \file include/use-case.h
3 * \brief use case interface for the ALSA driver
4 * \author Liam Girdwood <lrg@slimlogic.co.uk>
5 * \author Stefan Schmidt <stefan@slimlogic.co.uk>
6 * \author Jaroslav Kysela <perex@perex.cz>
7 * \author Justin Xu <justinx@slimlogic.co.uk>
12 * This library is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as
14 * published by the Free Software Foundation; either version 2.1 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Copyright (C) 2008-2010 SlimLogic Ltd
27 * Copyright (C) 2010 Wolfson Microelectronics PLC
28 * Copyright (C) 2010 Texas Instruments Inc.
30 * Support for the verb/device/modifier core logic and API,
31 * command line tool and file parser was kindly sponsored by
32 * Texas Instruments Inc.
33 * Support for multiple active modifiers and devices,
34 * transition sequences, multiple client access and user defined use
35 * cases was kindly sponsored by Wolfson Microelectronics PLC.
38 #ifndef __ALSA_USE_CASE_H
39 #define __ALSA_USE_CASE_H
46 * \defgroup Use Case Interface
47 * The ALSA Use Case manager interface.
48 * See \ref Usecase page for more details.
53 * ALSA Use Case Interface
55 * The use case manager works by configuring the sound card ALSA kcontrols to
56 * change the hardware digital and analog audio routing to match the requested
57 * device use case. The use case manager kcontrol configurations are stored in
58 * easy to modify text files.
60 * An audio use case can be defined by a verb and device parameter. The verb
61 * describes the use case action i.e. a phone call, listening to music, recording
62 * a conversation etc. The device describes the physical audio capture and playback
63 * hardware i.e. headphones, phone handset, bluetooth headset, etc.
65 * It's intended clients will mostly only need to set the use case verb and
66 * device for each system use case change (as the verb and device parameters
67 * cover most audio use cases).
69 * However there are times when a use case has to be modified at runtime. e.g.
71 * o Incoming phone call when the device is playing music
72 * o Recording sections of a phone call
73 * o Playing tones during a call.
75 * In order to allow asynchronous runtime use case adaptations, we have a third
76 * optional modifier parameter that can be used to further configure
77 * the use case during live audio runtime.
79 * This interface allows clients to :-
81 * o Query the supported use case verbs, devices and modifiers for the machine.
82 * o Set and Get use case verbs, devices and modifiers for the machine.
83 * o Get the ALSA PCM playback and capture device PCMs for use case verb and
85 * o Get the TQ parameter for each use case verb and modifier.
86 * o Get the ALSA master playback and capture volume/switch kcontrols
94 * The use case verb is the main device audio action. e.g. the "HiFi" use
95 * case verb will configure the audio hardware for HiFi Music playback
98 #define SND_USE_CASE_VERB_INACTIVE "Inactive"
99 #define SND_USE_CASE_VERB_HIFI "HiFi"
100 #define SND_USE_CASE_VERB_HIFI_LOW_POWER "HiFi Low Power"
101 #define SND_USE_CASE_VERB_VOICE "Voice"
102 #define SND_USE_CASE_VERB_VOICE_LOW_POWER "Voice Low Power"
103 #define SND_USE_CASE_VERB_VOICECALL "Voice Call"
104 #define SND_USE_CASE_VERB_IP_VOICECALL "Voice Call IP"
105 #define SND_USE_CASE_VERB_ANALOG_RADIO "FM Analog Radio"
106 #define SND_USE_CASE_VERB_DIGITAL_RADIO "FM Digital Radio"
107 /* add new verbs to end of list */
113 * Physical system devices the render and capture audio. Devices can be OR'ed
114 * together to support audio on similtanious devices.
116 #define SND_USE_CASE_DEV_NONE "None"
117 #define SND_USE_CASE_DEV_SPEAKER "Speaker"
118 #define SND_USE_CASE_DEV_LINE "Line"
119 #define SND_USE_CASE_DEV_HEADPHONES "Headphones"
120 #define SND_USE_CASE_DEV_HEADSET "Headset"
121 #define SND_USE_CASE_DEV_HANDSET "Handset"
122 #define SND_USE_CASE_DEV_BLUETOOTH "Bluetooth"
123 #define SND_USE_CASE_DEV_EARPIECE "Earpiece"
124 #define SND_USE_CASE_DEV_SPDIF "SPDIF"
125 #define SND_USE_CASE_DEV_HDMI "HDMI"
126 /* add new devices to end of list */
130 * Use Case Modifiers.
132 * The use case modifier allows runtime configuration changes to deal with
133 * asynchronous events.
135 * e.g. to record a voice call :-
136 * 1. Set verb to SND_USE_CASE_VERB_VOICECALL (for voice call)
137 * 2. Set modifier SND_USE_CASE_MOD_CAPTURE_VOICE when capture required.
138 * 3. Call snd_use_case_get("_pcm_/_cdevice") to get ALSA source PCM name
139 * with captured voice pcm data.
141 * e.g. to play a ring tone when listenin to MP3 Music :-
142 * 1. Set verb to SND_USE_CASE_VERB_HIFI (for MP3 playback)
143 * 2. Set modifier to SND_USE_CASE_MOD_PLAY_TONE when incoming call happens.
144 * 3. Call snd_use_case_get("_pcm_/_pdevice") to get ALSA PCM sink name for
147 #define SND_USE_CASE_MOD_CAPTURE_VOICE "Capture Voice"
148 #define SND_USE_CASE_MOD_CAPTURE_MUSIC "Capture Music"
149 #define SND_USE_CASE_MOD_PLAY_MUSIC "Play Music"
150 #define SND_USE_CASE_MOD_PLAY_VOICE "Play Voice"
151 #define SND_USE_CASE_MOD_PLAY_TONE "Play Tone"
152 #define SND_USE_CASE_MOD_ECHO_REF "Echo Reference"
153 /* add new modifiers to end of list */
159 * The interface allows clients to determine the audio TQ required for each
160 * use case verb and modifier. It's intended as an optional hint to the
161 * audio driver in order to lower power consumption.
164 #define SND_USE_CASE_TQ_MUSIC "Music"
165 #define SND_USE_CASE_TQ_VOICE "Voice"
166 #define SND_USE_CASE_TQ_TONES "Tones"
168 /** use case container */
169 typedef struct snd_use_case_mgr snd_use_case_mgr_t;
172 * \brief Create an identifier
173 * \param fmt Format (sprintf like)
174 * \param ... Optional arguments for sprintf like format
175 * \return Allocated string identifier or NULL on error
177 char *snd_use_case_identifier(const char *fmt, ...);
180 * \brief Free a string list
181 * \param list The string list to free
182 * \param items Count of strings
183 * \return Zero if success, otherwise a negative error code
185 int snd_use_case_free_list(const char *list[], int items);
188 * \brief Obtain a list of entries
189 * \param uc_mgr Use case manager (may be NULL - card list)
190 * \param identifier (may be NULL - card list)
191 * \param list Returned allocated list
192 * \return Number of list entries if success, otherwise a negative error code
194 * Defined identifiers:
195 * NULL - get card list
196 * (in pair cardname+comment)
197 * _verbs - get verb list
198 * (in pair verb+comment)
199 * _devices[/<verb>] - get list of supported devices
200 * (in pair device+comment)
201 * _modifiers[/<verb>]- get list of supported modifiers
202 * (in pair modifier+comment)
203 * TQ[/<verb>] - get list of TQ identifiers
204 * _enadevs - get list of enabled devices
205 * _enamods - get list of enabled modifiers
208 int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr,
209 const char *identifier,
210 const char **list[]);
214 * \brief Get current - string
215 * \param uc_mgr Use case manager
217 * \param value Value pointer
218 * \return Zero if success, otherwise a negative error code
220 * Note: String is dynamically allocated, use free() to
221 * deallocate this string.
224 * NULL - return current card
225 * _verb - return current verb
226 * TQ[/<modifier>] - Tone Quality [for given modifier]
227 * PlaybackPCM[/<modifier>] - full PCM playback device name
228 * CapturePCM[/<modifier>] - full PCM capture device name
229 * PlaybackCTL[/<modifier>] - playback control device name
230 * PlaybackVolume[/<modifier>] - playback control volume ID string
231 * PlaybackSwitch[/<modifier>] - playback control switch ID string
232 * CaptureCTL[/<modifier>] - capture control device name
233 * CaptureVolume[/<modifier>] - capture control volume ID string
234 * CaptureSwitch[/<modifier>] - capture control switch ID string
235 * PlaybackMixer[/<modifier>] - name of playback mixer
236 * PlaybackMixerID[/<modifier>] - mixer playback ID
237 * CaptureMixer[/<modifier>] - name of capture mixer
238 * CaptureMixerID[/<modifier>] - mixer capture ID
240 int snd_use_case_get(snd_use_case_mgr_t *uc_mgr,
241 const char *identifier,
245 * \brief Get current - integer
246 * \param uc_mgr Use case manager
248 * \param value result
249 * \return Zero if success, otherwise a negative error code
252 * _devstatus/<device> - return status for given device
253 * _modstatus/<modifier> - return status for given modifier
255 int snd_use_case_geti(snd_use_case_mgr_t *uc_mgr,
256 const char *identifier,
261 * \param uc_mgr Use case manager
264 * \return Zero if success, otherwise a negative error code
267 * _verb - set current verb = value
268 * _enadev - enable given device = value
269 * _disdev - disable given device = value
270 * _swdev/<old_device> - new_device = value
271 * - disable old_device and then enable new_device
272 * - if old_device is not enabled just return
273 * - check transmit sequence firstly
274 * _enamod - enable given modifier = value
275 * _dismod - disable given modifier = value
276 * _swmod/<old_modifier> - new_modifier = value
277 * - disable old_modifier and then enable new_modifier
278 * - if old_modifier is not enabled just return
279 * - check transmit sequence firstly
281 int snd_use_case_set(snd_use_case_mgr_t *uc_mgr,
282 const char *identifier,
286 * \brief Open and initialise use case core for sound card
287 * \param uc_mgr Returned use case manager pointer
288 * \param card_name Sound card name.
289 * \return zero if success, otherwise a negative error code
291 int snd_use_case_mgr_open(snd_use_case_mgr_t **uc_mgr, const char *card_name);
295 * \brief Reload and re-parse use case configuration files for sound card.
296 * \param uc_mgr Use case manager
297 * \return zero if success, otherwise a negative error code
299 int snd_use_case_mgr_reload(snd_use_case_mgr_t *uc_mgr);
302 * \brief Close use case manager
303 * \param uc_mgr Use case manager
304 * \return zero if success, otherwise a negative error code
306 int snd_use_case_mgr_close(snd_use_case_mgr_t *uc_mgr);
309 * \brief Reset use case manager verb, device, modifier to deafult settings.
310 * \param uc_mgr Use case manager
311 * \return zero if success, otherwise a negative error code
313 int snd_use_case_mgr_reset(snd_use_case_mgr_t *uc_mgr);
320 * \brief Obtain a list of cards
321 * \param list Returned allocated list
322 * \return Number of list entries if success, otherwise a negative error code
324 static inline int snd_use_case_card_list(const char **list[])
326 return snd_use_case_get_list(NULL, NULL, list);
330 * \brief Obtain a list of verbs
331 * \param uc_mgr Use case manager
332 * \param list Returned list of verbs
333 * \return Number of list entries if success, otherwise a negative error code
335 static inline int snd_use_case_verb_list(snd_use_case_mgr_t *uc_mgr,
338 return snd_use_case_get_list(uc_mgr, "_verbs", list);
349 #endif /* __ALSA_USE_CASE_H */