use-case.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. #ifndef __ALSA_USE_CASE_H
  38. #define __ALSA_USE_CASE_H
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /**
  43. * \defgroup ucm Use Case Interface
  44. * The ALSA Use Case manager interface.
  45. * See \ref Usecase page for more details.
  46. * \{
  47. */
  48. /*! \page Usecase ALSA Use Case Interface
  49. *
  50. * The use case manager works by configuring the sound card ALSA kcontrols to
  51. * change the hardware digital and analog audio routing to match the requested
  52. * device use case. The use case manager kcontrol configurations are stored in
  53. * easy to modify text files.
  54. *
  55. * An audio use case can be defined by a verb and device parameter. The verb
  56. * describes the use case action i.e. a phone call, listening to music, recording
  57. * a conversation etc. The device describes the physical audio capture and playback
  58. * hardware i.e. headphones, phone handset, bluetooth headset, etc.
  59. *
  60. * It's intended clients will mostly only need to set the use case verb and
  61. * device for each system use case change (as the verb and device parameters
  62. * cover most audio use cases).
  63. *
  64. * However there are times when a use case has to be modified at runtime. e.g.
  65. *
  66. * + Incoming phone call when the device is playing music
  67. * + Recording sections of a phone call
  68. * + Playing tones during a call.
  69. *
  70. * In order to allow asynchronous runtime use case adaptations, we have a third
  71. * optional modifier parameter that can be used to further configure
  72. * the use case during live audio runtime.
  73. *
  74. * This interface allows clients to :-
  75. *
  76. * + Query the supported use case verbs, devices and modifiers for the machine.
  77. * + Set and Get use case verbs, devices and modifiers for the machine.
  78. * + Get the ALSA PCM playback and capture device PCMs for use case verb,
  79. * use case device and modifier.
  80. * + Get the TQ parameter for each use case verb, use case device and
  81. * modifier.
  82. * + Get the ALSA master playback and capture volume/switch kcontrols
  83. * for each use case.
  84. */
  85. /*
  86. * Use Case Verb.
  87. *
  88. * The use case verb is the main device audio action. e.g. the "HiFi" use
  89. * case verb will configure the audio hardware for HiFi Music playback
  90. * and capture.
  91. */
  92. #define SND_USE_CASE_VERB_INACTIVE "Inactive" /**< Inactive Verb */
  93. #define SND_USE_CASE_VERB_HIFI "HiFi" /**< HiFi Verb */
  94. #define SND_USE_CASE_VERB_HIFI_LOW_POWER "HiFi Low Power" /**< HiFi Low Power Verb */
  95. #define SND_USE_CASE_VERB_VOICE "Voice" /**< Voice Verb */
  96. #define SND_USE_CASE_VERB_VOICE_LOW_POWER "Voice Low Power" /**< Voice Low Power Verb */
  97. #define SND_USE_CASE_VERB_VOICECALL "Voice Call" /**< Voice Call Verb */
  98. #define SND_USE_CASE_VERB_IP_VOICECALL "Voice Call IP" /**< Voice Call IP Verb */
  99. #define SND_USE_CASE_VERB_ANALOG_RADIO "FM Analog Radio" /**< FM Analog Radio Verb */
  100. #define SND_USE_CASE_VERB_DIGITAL_RADIO "FM Digital Radio" /**< FM Digital Radio Verb */
  101. /* add new verbs to end of list */
  102. /*
  103. * Use Case Device.
  104. *
  105. * Physical system devices the render and capture audio. Devices can be OR'ed
  106. * together to support audio on simultaneous devices.
  107. */
  108. #define SND_USE_CASE_DEV_NONE "None" /**< None Device */
  109. #define SND_USE_CASE_DEV_SPEAKER "Speaker" /**< Speaker Device */
  110. #define SND_USE_CASE_DEV_LINE "Line" /**< Line Device */
  111. #define SND_USE_CASE_DEV_HEADPHONES "Headphones" /**< Headphones Device */
  112. #define SND_USE_CASE_DEV_HEADSET "Headset" /**< Headset Device */
  113. #define SND_USE_CASE_DEV_HANDSET "Handset" /**< Handset Device */
  114. #define SND_USE_CASE_DEV_BLUETOOTH "Bluetooth" /**< Bluetooth Device */
  115. #define SND_USE_CASE_DEV_EARPIECE "Earpiece" /**< Earpiece Device */
  116. #define SND_USE_CASE_DEV_SPDIF "SPDIF" /**< SPDIF Device */
  117. #define SND_USE_CASE_DEV_HDMI "HDMI" /**< HDMI Device */
  118. /* add new devices to end of list */
  119. /*
  120. * Use Case Modifiers.
  121. *
  122. * The use case modifier allows runtime configuration changes to deal with
  123. * asynchronous events.
  124. *
  125. * e.g. to record a voice call :-
  126. * 1. Set verb to SND_USE_CASE_VERB_VOICECALL (for voice call)
  127. * 2. Set modifier SND_USE_CASE_MOD_CAPTURE_VOICE when capture required.
  128. * 3. Call snd_use_case_get("CapturePCM") to get ALSA source PCM name
  129. * with captured voice pcm data.
  130. *
  131. * e.g. to play a ring tone when listenin to MP3 Music :-
  132. * 1. Set verb to SND_USE_CASE_VERB_HIFI (for MP3 playback)
  133. * 2. Set modifier to SND_USE_CASE_MOD_PLAY_TONE when incoming call happens.
  134. * 3. Call snd_use_case_get("PlaybackPCM") to get ALSA PCM sink name for
  135. * ringtone pcm data.
  136. */
  137. #define SND_USE_CASE_MOD_CAPTURE_VOICE "Capture Voice" /**< Capture Voice Modifier */
  138. #define SND_USE_CASE_MOD_CAPTURE_MUSIC "Capture Music" /**< Capture Music Modifier */
  139. #define SND_USE_CASE_MOD_PLAY_MUSIC "Play Music" /**< Play Music Modifier */
  140. #define SND_USE_CASE_MOD_PLAY_VOICE "Play Voice" /**< Play Voice Modifier */
  141. #define SND_USE_CASE_MOD_PLAY_TONE "Play Tone" /**< Play Tone Modifier */
  142. #define SND_USE_CASE_MOD_ECHO_REF "Echo Reference" /**< Echo Reference Modifier */
  143. /* add new modifiers to end of list */
  144. /**
  145. * TQ - Tone Quality
  146. *
  147. * The interface allows clients to determine the audio TQ required for each
  148. * use case verb and modifier. It's intended as an optional hint to the
  149. * audio driver in order to lower power consumption.
  150. *
  151. */
  152. #define SND_USE_CASE_TQ_MUSIC "Music" /**< Music Tone Quality */
  153. #define SND_USE_CASE_TQ_VOICE "Voice" /**< Voice Tone Quality */
  154. #define SND_USE_CASE_TQ_TONES "Tones" /**< Tones Tone Quality */
  155. /** use case container */
  156. typedef struct snd_use_case_mgr snd_use_case_mgr_t;
  157. /**
  158. * \brief Create an identifier
  159. * \param fmt Format (sprintf like)
  160. * \param ... Optional arguments for sprintf like format
  161. * \return Allocated string identifier or NULL on error
  162. */
  163. char *snd_use_case_identifier(const char *fmt, ...);
  164. /**
  165. * \brief Free a string list
  166. * \param list The string list to free
  167. * \param items Count of strings
  168. * \return Zero if success, otherwise a negative error code
  169. */
  170. int snd_use_case_free_list(const char *list[], int items);
  171. /**
  172. * \brief Obtain a list of entries
  173. * \param uc_mgr Use case manager (may be NULL - card list)
  174. * \param identifier (may be NULL - card list)
  175. * \param list Returned allocated list
  176. * \return Number of list entries if success, otherwise a negative error code
  177. *
  178. * Defined identifiers:
  179. * NULL - get card list
  180. * (in pair cardname+comment)
  181. * _verbs - get verb list
  182. * (in pair verb+comment)
  183. * _devices[/{verb}] - get list of supported devices
  184. * (in pair device+comment)
  185. * _modifiers[/{verb}]- get list of supported modifiers
  186. * (in pair modifier+comment)
  187. * TQ[/{verb}] - get list of TQ identifiers
  188. * _enadevs - get list of enabled devices
  189. * _enamods - get list of enabled modifiers
  190. *
  191. * _supporteddevs/{modifier}|{device}[/{verb}] - list of supported devices
  192. * _conflictingdevs/{modifier}|{device}[/{verb}] - list of conflicting devices
  193. * Note that at most one of the supported/conflicting devs lists has
  194. * any entries, and when neither is present, all devices are supported.
  195. *
  196. */
  197. int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr,
  198. const char *identifier,
  199. const char **list[]);
  200. /**
  201. * \brief Get current - string
  202. * \param uc_mgr Use case manager
  203. * \param identifier
  204. * \param value Value pointer
  205. * \return Zero if success, otherwise a negative error code
  206. *
  207. * Note: The returned string is dynamically allocated, use free() to
  208. * deallocate this string. (Yes, the value parameter shouldn't be marked as
  209. * "const", but it's too late to fix it, sorry about that.)
  210. *
  211. * Known identifiers:
  212. * - NULL - return current card
  213. * - _verb - return current verb
  214. *
  215. * - [=]{NAME}[/[{modifier}|{/device}][/{verb}]]
  216. * - value identifier {NAME}
  217. * - Search starts at given modifier or device if any,
  218. * else at a verb
  219. * - Search starts at given verb if any,
  220. * else current verb
  221. * - Searches modifier/device, then verb, then defaults
  222. * - Specify a leading "=" to search only the exact
  223. * device/modifier/verb specified, and not search
  224. * through each object in turn.
  225. * - Examples:
  226. * - "PlaybackPCM/Play Music"
  227. * - "CapturePCM/SPDIF"
  228. * - From ValueDefaults only:
  229. * "=Variable"
  230. * - From current active verb:
  231. * "=Variable//"
  232. * - From verb "Verb":
  233. * "=Variable//Verb"
  234. * - From "Modifier" in current active verb:
  235. * "=Variable/Modifier/"
  236. * - From "Modifier" in "Verb":
  237. * "=Variable/Modifier/Verb"
  238. *
  239. * Recommended names for values:
  240. * - TQ
  241. * - Tone Quality
  242. * - PlaybackPCM
  243. * - full PCM playback device name
  244. * - PlaybackPCMIsDummy
  245. * - Valid values: "yes" and "no". If set to "yes", the PCM named by the
  246. * PlaybackPCM value is a dummy device, meaning that opening it enables
  247. * an audio path in the hardware, but writing to the PCM device has no
  248. * effect.
  249. * - CapturePCM
  250. * - full PCM capture device name
  251. * - CapturePCMIsDummy
  252. * - Valid values: "yes" and "no". If set to "yes", the PCM named by the
  253. * CapturePCM value is a dummy device, meaning that opening it enables
  254. * an audio path in the hardware, but reading from the PCM device has no
  255. * effect.
  256. * - PlaybackRate
  257. * - playback device sample rate
  258. * - PlaybackChannels
  259. * - playback device channel count
  260. * - PlaybackCTL
  261. * - playback control device name
  262. * - PlaybackVolume
  263. * - playback control volume ID string
  264. * - PlaybackSwitch
  265. * - playback control switch ID string
  266. * - CaptureRate
  267. * - capture device sample rate
  268. * - CaptureChannels
  269. * - capture device channel count
  270. * - CaptureCTL
  271. * - capture control device name
  272. * - CaptureVolume
  273. * - capture control volume ID string
  274. * - CaptureSwitch
  275. * - capture control switch ID string
  276. * - PlaybackMixer
  277. * - name of playback mixer
  278. * - PlaybackMixerID
  279. * - mixer playback ID
  280. * - CaptureMixer
  281. * - name of capture mixer
  282. * - CaptureMixerID
  283. * - mixer capture ID
  284. * - JackControl, JackDev, JackHWMute
  285. * - Jack information for a device. The jack status can be reported via
  286. * a kcontrol and/or via an input device. **JackControl** is the
  287. * kcontrol name of the jack, and **JackDev** is the input device id of
  288. * the jack (if the full input device path is /dev/input/by-id/foo, the
  289. * JackDev value should be "foo"). UCM configuration files should
  290. * contain both JackControl and JackDev when possible, because
  291. * applications are likely to support only one or the other.
  292. *
  293. * If **JackHWMute** is set, it indicates that when the jack is plugged
  294. * in, the hardware automatically mutes some other device(s). The
  295. * JackHWMute value is a space-separated list of device names (this
  296. * isn't compatible with device names with spaces in them, so don't use
  297. * such device names!). Note that JackHWMute should be used only when
  298. * the hardware enforces the automatic muting. If the hardware doesn't
  299. * enforce any muting, it may still be tempting to set JackHWMute to
  300. * trick upper software layers to e.g. automatically mute speakers when
  301. * headphones are plugged in, but that's application policy
  302. * configuration that doesn't belong to UCM configuration files.
  303. */
  304. int snd_use_case_get(snd_use_case_mgr_t *uc_mgr,
  305. const char *identifier,
  306. const char **value);
  307. /**
  308. * \brief Get current - integer
  309. * \param uc_mgr Use case manager
  310. * \param identifier
  311. * \param value result
  312. * \return Zero if success, otherwise a negative error code
  313. *
  314. * Known identifiers:
  315. * _devstatus/{device} - return status for given device
  316. * _modstatus/{modifier} - return status for given modifier
  317. */
  318. int snd_use_case_geti(snd_use_case_mgr_t *uc_mgr,
  319. const char *identifier,
  320. long *value);
  321. /**
  322. * \brief Set new
  323. * \param uc_mgr Use case manager
  324. * \param identifier
  325. * \param value Value
  326. * \return Zero if success, otherwise a negative error code
  327. *
  328. * Known identifiers:
  329. * _verb - set current verb = value
  330. * _enadev - enable given device = value
  331. * _disdev - disable given device = value
  332. * _swdev/{old_device} - new_device = value
  333. * - disable old_device and then enable new_device
  334. * - if old_device is not enabled just return
  335. * - check transmit sequence firstly
  336. * _enamod - enable given modifier = value
  337. * _dismod - disable given modifier = value
  338. * _swmod/{old_modifier} - new_modifier = value
  339. * - disable old_modifier and then enable new_modifier
  340. * - if old_modifier is not enabled just return
  341. * - check transmit sequence firstly
  342. */
  343. int snd_use_case_set(snd_use_case_mgr_t *uc_mgr,
  344. const char *identifier,
  345. const char *value);
  346. /**
  347. * \brief Open and initialise use case core for sound card
  348. * \param uc_mgr Returned use case manager pointer
  349. * \param card_name Sound card name.
  350. * \return zero if success, otherwise a negative error code
  351. */
  352. int snd_use_case_mgr_open(snd_use_case_mgr_t **uc_mgr, const char *card_name);
  353. /**
  354. * \brief Reload and re-parse use case configuration files for sound card.
  355. * \param uc_mgr Use case manager
  356. * \return zero if success, otherwise a negative error code
  357. */
  358. int snd_use_case_mgr_reload(snd_use_case_mgr_t *uc_mgr);
  359. /**
  360. * \brief Close use case manager
  361. * \param uc_mgr Use case manager
  362. * \return zero if success, otherwise a negative error code
  363. */
  364. int snd_use_case_mgr_close(snd_use_case_mgr_t *uc_mgr);
  365. /**
  366. * \brief Reset use case manager verb, device, modifier to deafult settings.
  367. * \param uc_mgr Use case manager
  368. * \return zero if success, otherwise a negative error code
  369. */
  370. int snd_use_case_mgr_reset(snd_use_case_mgr_t *uc_mgr);
  371. /*
  372. * helper functions
  373. */
  374. /**
  375. * \brief Obtain a list of cards
  376. * \param list Returned allocated list
  377. * \return Number of list entries if success, otherwise a negative error code
  378. */
  379. static __inline__ int snd_use_case_card_list(const char **list[])
  380. {
  381. return snd_use_case_get_list(NULL, NULL, list);
  382. }
  383. /**
  384. * \brief Obtain a list of verbs
  385. * \param uc_mgr Use case manager
  386. * \param list Returned list of verbs
  387. * \return Number of list entries if success, otherwise a negative error code
  388. */
  389. static __inline__ int snd_use_case_verb_list(snd_use_case_mgr_t *uc_mgr,
  390. const char **list[])
  391. {
  392. return snd_use_case_get_list(uc_mgr, "_verbs", list);
  393. }
  394. /**
  395. * \}
  396. */
  397. #ifdef __cplusplus
  398. }
  399. #endif
  400. #endif /* __ALSA_USE_CASE_H */