Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1 | /** |
| 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> |
| 8 | * \date 2008-2010 |
| 9 | */ |
| 10 | /* |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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 |
| 25 | * |
| 26 | * Copyright (C) 2008-2010 SlimLogic Ltd |
| 27 | * Copyright (C) 2010 Wolfson Microelectronics PLC |
| 28 | * Copyright (C) 2010 Texas Instruments Inc. |
| 29 | * |
| 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. |
| 36 | */ |
| 37 | |
| 38 | #ifndef __ALSA_USE_CASE_H |
| 39 | #define __ALSA_USE_CASE_H |
| 40 | |
| 41 | #ifdef __cplusplus |
| 42 | extern "C" { |
| 43 | #endif |
| 44 | |
| 45 | /** |
| 46 | * \defgroup Use Case Interface |
| 47 | * The ALSA Use Case manager interface. |
| 48 | * See \ref Usecase page for more details. |
| 49 | * \{ |
| 50 | */ |
| 51 | |
| 52 | /** |
| 53 | * ALSA Use Case Interface |
| 54 | * |
| 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. |
| 59 | * |
| 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. |
| 64 | * |
| 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). |
| 68 | * |
| 69 | * However there are times when a use case has to be modified at runtime. e.g. |
| 70 | * |
| 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. |
| 74 | * |
| 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. |
| 78 | * |
| 79 | * This interface allows clients to :- |
| 80 | * |
| 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, |
| 84 | * use case device and modifier. |
| 85 | * o Get the TQ parameter for each use case verb, use case device and |
| 86 | * modifier. |
| 87 | * o Get the ALSA master playback and capture volume/switch kcontrols |
| 88 | * for each use case. |
| 89 | */ |
| 90 | |
| 91 | |
| 92 | /* |
| 93 | * Use Case Verb. |
| 94 | * |
| 95 | * The use case verb is the main device audio action. e.g. the "HiFi" use |
| 96 | * case verb will configure the audio hardware for HiFi Music playback |
| 97 | * and capture. |
| 98 | */ |
| 99 | #define SND_USE_CASE_VERB_INACTIVE "Inactive" |
| 100 | #define SND_USE_CASE_VERB_HIFI "HiFi" |
| 101 | #define SND_USE_CASE_VERB_HIFI_LOW_POWER "HiFi Low Power" |
| 102 | #define SND_USE_CASE_VERB_VOICE "Voice" |
| 103 | #define SND_USE_CASE_VERB_VOICE_LOW_POWER "Voice Low Power" |
| 104 | #define SND_USE_CASE_VERB_VOICECALL "Voice Call" |
| 105 | #define SND_USE_CASE_VERB_IP_VOICECALL "Voice Call IP" |
| 106 | #define SND_USE_CASE_VERB_ANALOG_RADIO "FM Analog Radio" |
| 107 | #define SND_USE_CASE_VERB_DIGITAL_RADIO "FM Digital Radio" |
| 108 | /* add new verbs to end of list */ |
| 109 | |
| 110 | |
| 111 | /* |
| 112 | * Use Case Device. |
| 113 | * |
| 114 | * Physical system devices the render and capture audio. Devices can be OR'ed |
| 115 | * together to support audio on simultaneous devices. |
| 116 | */ |
| 117 | #define SND_USE_CASE_DEV_NONE "None" |
| 118 | #define SND_USE_CASE_DEV_SPEAKER "Speaker" |
| 119 | #define SND_USE_CASE_DEV_LINE "Line" |
| 120 | #define SND_USE_CASE_DEV_HEADPHONES "Headphones" |
| 121 | #define SND_USE_CASE_DEV_HEADSET "Headset" |
| 122 | #define SND_USE_CASE_DEV_HANDSET "Handset" |
| 123 | #define SND_USE_CASE_DEV_BLUETOOTH "Bluetooth" |
| 124 | #define SND_USE_CASE_DEV_EARPIECE "Earpiece" |
| 125 | #define SND_USE_CASE_DEV_SPDIF "SPDIF" |
| 126 | #define SND_USE_CASE_DEV_HDMI "HDMI" |
Araemo | ac92140 | 2013-04-06 19:20:45 +0000 | [diff] [blame] | 127 | #define SND_USE_CASE_DEV_DOCK "Dock" |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 128 | /* add new devices to end of list */ |
| 129 | |
| 130 | |
| 131 | /* |
| 132 | * Use Case Modifiers. |
| 133 | * |
| 134 | * The use case modifier allows runtime configuration changes to deal with |
| 135 | * asynchronous events. |
| 136 | * |
| 137 | * e.g. to record a voice call :- |
| 138 | * 1. Set verb to SND_USE_CASE_VERB_VOICECALL (for voice call) |
| 139 | * 2. Set modifier SND_USE_CASE_MOD_CAPTURE_VOICE when capture required. |
| 140 | * 3. Call snd_use_case_get("CapturePCM") to get ALSA source PCM name |
| 141 | * with captured voice pcm data. |
| 142 | * |
| 143 | * e.g. to play a ring tone when listenin to MP3 Music :- |
| 144 | * 1. Set verb to SND_USE_CASE_VERB_HIFI (for MP3 playback) |
| 145 | * 2. Set modifier to SND_USE_CASE_MOD_PLAY_TONE when incoming call happens. |
| 146 | * 3. Call snd_use_case_get("PlaybackPCM") to get ALSA PCM sink name for |
| 147 | * ringtone pcm data. |
| 148 | */ |
| 149 | #define SND_USE_CASE_MOD_CAPTURE_VOICE "Capture Voice" |
| 150 | #define SND_USE_CASE_MOD_CAPTURE_MUSIC "Capture Music" |
| 151 | #define SND_USE_CASE_MOD_PLAY_MUSIC "Play Music" |
| 152 | #define SND_USE_CASE_MOD_PLAY_VOICE "Play Voice" |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 153 | #define SND_USE_CASE_MOD_PLAY_TONE "Play Tone" |
| 154 | #define SND_USE_CASE_MOD_ECHO_REF "Echo Reference" |
| 155 | /* add new modifiers to end of list */ |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * TQ - Tone Quality |
| 160 | * |
| 161 | * The interface allows clients to determine the audio TQ required for each |
| 162 | * use case verb and modifier. It's intended as an optional hint to the |
| 163 | * audio driver in order to lower power consumption. |
| 164 | * |
| 165 | */ |
| 166 | #define SND_USE_CASE_TQ_MUSIC "Music" |
| 167 | #define SND_USE_CASE_TQ_VOICE "Voice" |
| 168 | #define SND_USE_CASE_TQ_TONES "Tones" |
| 169 | |
| 170 | /** use case container */ |
| 171 | typedef struct snd_use_case_mgr snd_use_case_mgr_t; |
| 172 | |
| 173 | /** |
| 174 | * \brief Create an identifier |
| 175 | * \param fmt Format (sprintf like) |
| 176 | * \param ... Optional arguments for sprintf like format |
| 177 | * \return Allocated string identifier or NULL on error |
| 178 | */ |
| 179 | char *snd_use_case_identifier(const char *fmt, ...); |
| 180 | |
| 181 | /** |
| 182 | * \brief Free a string list |
| 183 | * \param list The string list to free |
| 184 | * \param items Count of strings |
| 185 | * \return Zero if success, otherwise a negative error code |
| 186 | */ |
| 187 | int snd_use_case_free_list(const char *list[], int items); |
| 188 | |
| 189 | /** |
| 190 | * \brief Obtain a list of entries |
| 191 | * \param uc_mgr Use case manager (may be NULL - card list) |
| 192 | * \param identifier (may be NULL - card list) |
| 193 | * \param list Returned allocated list |
| 194 | * \return Number of list entries if success, otherwise a negative error code |
| 195 | * |
| 196 | * Defined identifiers: |
| 197 | * NULL - get card list |
| 198 | * (in pair cardname+comment) |
| 199 | * _verbs - get verb list |
| 200 | * (in pair verb+comment) |
| 201 | * _devices[/<verb>] - get list of supported devices |
| 202 | * (in pair device+comment) |
| 203 | * _modifiers[/<verb>]- get list of supported modifiers |
| 204 | * (in pair modifier+comment) |
| 205 | * TQ[/<verb>] - get list of TQ identifiers |
| 206 | * _enadevs - get list of enabled devices |
| 207 | * _enamods - get list of enabled modifiers |
| 208 | * |
| 209 | * _supporteddevs/<modifier>|<device>[/<verb>] - list of supported devices |
| 210 | * _conflictingdevs/<modifier>|<device>[/<verb>] - list of conflicting devices |
| 211 | * Note that at most one of the supported/conflicting devs lists has |
| 212 | * any entries, and when neither is present, all devices are supported. |
| 213 | * |
| 214 | */ |
| 215 | int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, |
| 216 | const char *identifier, |
| 217 | const char **list[]); |
| 218 | |
| 219 | |
| 220 | /** |
| 221 | * \brief Get current - string |
| 222 | * \param uc_mgr Use case manager |
| 223 | * \param identifier |
| 224 | * \param value Value pointer |
| 225 | * \return Zero if success, otherwise a negative error code |
| 226 | * |
| 227 | * Note: String is dynamically allocated, use free() to |
| 228 | * deallocate this string. |
| 229 | * |
| 230 | * Known identifiers: |
| 231 | * NULL - return current card |
| 232 | * _verb - return current verb |
| 233 | * |
| 234 | * [=]<NAME>[/[<modifier>|</device>][/<verb>]] |
| 235 | * - value identifier <NAME> |
| 236 | * - Search starts at given modifier or device if any, |
| 237 | * else at a verb |
| 238 | * - Search starts at given verb if any, |
| 239 | * else current verb |
| 240 | * - Searches modifier/device, then verb, then defaults |
| 241 | * - Specify a leading "=" to search only the exact |
| 242 | * device/modifier/verb specified, and not search |
| 243 | * through each object in turn. |
| 244 | * - Examples: |
| 245 | * "PlaybackPCM/Play Music" |
| 246 | * "CapturePCM/SPDIF" |
| 247 | * From ValueDefaults only: |
| 248 | * "=Variable" |
| 249 | * From current active verb: |
| 250 | * "=Variable//" |
| 251 | * From verb "Verb": |
| 252 | * "=Variable//Verb" |
| 253 | * From "Modifier" in current active verb: |
| 254 | * "=Variable/Modifier/" |
| 255 | * From "Modifier" in "Verb": |
| 256 | * "=Variable/Modifier/Verb" |
| 257 | * |
| 258 | * Recommended names for values: |
| 259 | * TQ - Tone Quality |
| 260 | * PlaybackPCM - full PCM playback device name |
| 261 | * CapturePCM - full PCM capture device name |
| 262 | * PlaybackCTL - playback control device name |
| 263 | * PlaybackVolume - playback control volume ID string |
| 264 | * PlaybackSwitch - playback control switch ID string |
| 265 | * CaptureCTL - capture control device name |
| 266 | * CaptureVolume - capture control volume ID string |
| 267 | * CaptureSwitch - capture control switch ID string |
| 268 | * PlaybackMixer - name of playback mixer |
| 269 | * PlaybackMixerID - mixer playback ID |
| 270 | * CaptureMixer - name of capture mixer |
| 271 | * CaptureMixerID - mixer capture ID |
| 272 | */ |
| 273 | int snd_use_case_get(snd_use_case_mgr_t *uc_mgr, |
| 274 | const char *identifier, |
| 275 | const char **value); |
| 276 | |
| 277 | /** |
| 278 | * \brief Get current - integer |
| 279 | * \param uc_mgr Use case manager |
| 280 | * \param identifier |
| 281 | * \param value result |
| 282 | * \return Zero if success, otherwise a negative error code |
| 283 | * |
| 284 | * Known identifiers: |
| 285 | * _devstatus/<device> - return status for given device |
| 286 | * _modstatus/<modifier> - return status for given modifier |
| 287 | */ |
| 288 | int snd_use_case_geti(snd_use_case_mgr_t *uc_mgr, |
| 289 | const char *identifier, |
| 290 | long *value); |
| 291 | |
| 292 | /** |
| 293 | * \brief Set new |
| 294 | * \param uc_mgr Use case manager |
| 295 | * \param identifier |
| 296 | * \param value Value |
| 297 | * \return Zero if success, otherwise a negative error code |
| 298 | * |
| 299 | * Known identifiers: |
| 300 | * _verb - set current verb = value |
| 301 | * _enadev - enable given device = value |
| 302 | * _disdev - disable given device = value |
| 303 | * _swdev/<old_device> - new_device = value |
| 304 | * - disable old_device and then enable new_device |
| 305 | * - if old_device is not enabled just return |
| 306 | * - check transmit sequence firstly |
| 307 | * _enamod - enable given modifier = value |
| 308 | * _dismod - disable given modifier = value |
| 309 | * _swmod/<old_modifier> - new_modifier = value |
| 310 | * - disable old_modifier and then enable new_modifier |
| 311 | * - if old_modifier is not enabled just return |
| 312 | * - check transmit sequence firstly |
| 313 | */ |
| 314 | int snd_use_case_set(snd_use_case_mgr_t *uc_mgr, |
| 315 | const char *identifier, |
| 316 | const char *value); |
| 317 | |
| 318 | /** |
| 319 | * \brief Open and initialise use case core for sound card |
| 320 | * \param uc_mgr Returned use case manager pointer |
| 321 | * \param card_name Sound card name. |
| 322 | * \return zero if success, otherwise a negative error code |
| 323 | */ |
| 324 | int snd_use_case_mgr_open(snd_use_case_mgr_t **uc_mgr, const char *card_name); |
| 325 | |
| 326 | |
| 327 | /** |
| 328 | * \brief Reload and re-parse use case configuration files for sound card. |
| 329 | * \param uc_mgr Use case manager |
| 330 | * \return zero if success, otherwise a negative error code |
| 331 | */ |
| 332 | int snd_use_case_mgr_reload(snd_use_case_mgr_t *uc_mgr); |
| 333 | |
| 334 | /** |
| 335 | * \brief Close use case manager |
| 336 | * \param uc_mgr Use case manager |
| 337 | * \return zero if success, otherwise a negative error code |
| 338 | */ |
| 339 | int snd_use_case_mgr_close(snd_use_case_mgr_t *uc_mgr); |
| 340 | |
| 341 | /** |
| 342 | * \brief Reset use case manager verb, device, modifier to deafult settings. |
| 343 | * \param uc_mgr Use case manager |
| 344 | * \return zero if success, otherwise a negative error code |
| 345 | */ |
| 346 | int snd_use_case_mgr_reset(snd_use_case_mgr_t *uc_mgr); |
| 347 | |
| 348 | /* |
| 349 | * helper functions |
| 350 | */ |
| 351 | |
| 352 | /** |
| 353 | * \brief Obtain a list of cards |
| 354 | * \param list Returned allocated list |
| 355 | * \return Number of list entries if success, otherwise a negative error code |
| 356 | */ |
| 357 | static inline int snd_use_case_card_list(const char **list[]) |
| 358 | { |
| 359 | return snd_use_case_get_list(NULL, NULL, list); |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * \brief Obtain a list of verbs |
| 364 | * \param uc_mgr Use case manager |
| 365 | * \param list Returned list of verbs |
| 366 | * \return Number of list entries if success, otherwise a negative error code |
| 367 | */ |
| 368 | static inline int snd_use_case_verb_list(snd_use_case_mgr_t *uc_mgr, |
| 369 | const char **list[]) |
| 370 | { |
| 371 | return snd_use_case_get_list(uc_mgr, "_verbs", list); |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * \} |
| 376 | */ |
| 377 | |
| 378 | #ifdef __cplusplus |
| 379 | } |
| 380 | #endif |
| 381 | |
| 382 | #endif /* __ALSA_USE_CASE_H */ |