Path: blob/master/thirdparty/linuxbsd_headers/alsa/use-case.h
9903 views
/**1* \file include/use-case.h2* \brief use case interface for the ALSA driver3* \author Liam Girdwood <[email protected]>4* \author Stefan Schmidt <[email protected]>5* \author Jaroslav Kysela <[email protected]>6* \author Justin Xu <[email protected]>7* \date 2008-20108*/9/*10*11* This library is free software; you can redistribute it and/or modify12* it under the terms of the GNU Lesser General Public License as13* published by the Free Software Foundation; either version 2.1 of14* the License, or (at your option) any later version.15*16* This program is distributed in the hope that it will be useful,17* but WITHOUT ANY WARRANTY; without even the implied warranty of18* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19* GNU Lesser General Public License for more details.20*21* You should have received a copy of the GNU Lesser General Public22* License along with this library; if not, write to the Free Software23* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA24*25* Copyright (C) 2008-2010 SlimLogic Ltd26* Copyright (C) 2010 Wolfson Microelectronics PLC27* Copyright (C) 2010 Texas Instruments Inc.28*29* Support for the verb/device/modifier core logic and API,30* command line tool and file parser was kindly sponsored by31* Texas Instruments Inc.32* Support for multiple active modifiers and devices,33* transition sequences, multiple client access and user defined use34* cases was kindly sponsored by Wolfson Microelectronics PLC.35*/3637#ifndef __ALSA_USE_CASE_H38#define __ALSA_USE_CASE_H3940#ifdef __cplusplus41extern "C" {42#endif4344/**45* \defgroup ucm Use Case Interface46* The ALSA Use Case manager interface.47* See \ref Usecase page for more details.48* \{49*/5051/*! \page Usecase ALSA Use Case Interface52*53* The use case manager works by configuring the sound card ALSA kcontrols to54* change the hardware digital and analog audio routing to match the requested55* device use case. The use case manager kcontrol configurations are stored in56* easy to modify text files.57*58* An audio use case can be defined by a verb and device parameter. The verb59* describes the use case action i.e. a phone call, listening to music, recording60* a conversation etc. The device describes the physical audio capture and playback61* hardware i.e. headphones, phone handset, bluetooth headset, etc.62*63* It's intended clients will mostly only need to set the use case verb and64* device for each system use case change (as the verb and device parameters65* cover most audio use cases).66*67* However there are times when a use case has to be modified at runtime. e.g.68*69* + Incoming phone call when the device is playing music70* + Recording sections of a phone call71* + Playing tones during a call.72*73* In order to allow asynchronous runtime use case adaptations, we have a third74* optional modifier parameter that can be used to further configure75* the use case during live audio runtime.76*77* This interface allows clients to :-78*79* + Query the supported use case verbs, devices and modifiers for the machine.80* + Set and Get use case verbs, devices and modifiers for the machine.81* + Get the ALSA PCM playback and capture device PCMs for use case verb,82* use case device and modifier.83* + Get the TQ parameter for each use case verb, use case device and84* modifier.85* + Get the ALSA master playback and capture volume/switch kcontrols86* for each use case.87*/888990/*91* Use Case Verb.92*93* The use case verb is the main device audio action. e.g. the "HiFi" use94* case verb will configure the audio hardware for HiFi Music playback95* and capture.96*/97#define SND_USE_CASE_VERB_INACTIVE "Inactive" /**< Inactive Verb */98#define SND_USE_CASE_VERB_HIFI "HiFi" /**< HiFi Verb */99#define SND_USE_CASE_VERB_HIFI_LOW_POWER "HiFi Low Power" /**< HiFi Low Power Verb */100#define SND_USE_CASE_VERB_VOICE "Voice" /**< Voice Verb */101#define SND_USE_CASE_VERB_VOICE_LOW_POWER "Voice Low Power" /**< Voice Low Power Verb */102#define SND_USE_CASE_VERB_VOICECALL "Voice Call" /**< Voice Call Verb */103#define SND_USE_CASE_VERB_IP_VOICECALL "Voice Call IP" /**< Voice Call IP Verb */104#define SND_USE_CASE_VERB_ANALOG_RADIO "FM Analog Radio" /**< FM Analog Radio Verb */105#define SND_USE_CASE_VERB_DIGITAL_RADIO "FM Digital Radio" /**< FM Digital Radio Verb */106/* add new verbs to end of list */107108109/*110* Use Case Device.111*112* Physical system devices the render and capture audio. Devices can be OR'ed113* together to support audio on simultaneous devices.114*/115#define SND_USE_CASE_DEV_NONE "None" /**< None Device */116#define SND_USE_CASE_DEV_SPEAKER "Speaker" /**< Speaker Device */117#define SND_USE_CASE_DEV_LINE "Line" /**< Line Device */118#define SND_USE_CASE_DEV_HEADPHONES "Headphones" /**< Headphones Device */119#define SND_USE_CASE_DEV_HEADSET "Headset" /**< Headset Device */120#define SND_USE_CASE_DEV_HANDSET "Handset" /**< Handset Device */121#define SND_USE_CASE_DEV_BLUETOOTH "Bluetooth" /**< Bluetooth Device */122#define SND_USE_CASE_DEV_EARPIECE "Earpiece" /**< Earpiece Device */123#define SND_USE_CASE_DEV_SPDIF "SPDIF" /**< SPDIF Device */124#define SND_USE_CASE_DEV_HDMI "HDMI" /**< HDMI Device */125/* add new devices to end of list */126127128/*129* Use Case Modifiers.130*131* The use case modifier allows runtime configuration changes to deal with132* asynchronous events.133*134* e.g. to record a voice call :-135* 1. Set verb to SND_USE_CASE_VERB_VOICECALL (for voice call)136* 2. Set modifier SND_USE_CASE_MOD_CAPTURE_VOICE when capture required.137* 3. Call snd_use_case_get("CapturePCM") to get ALSA source PCM name138* with captured voice pcm data.139*140* e.g. to play a ring tone when listenin to MP3 Music :-141* 1. Set verb to SND_USE_CASE_VERB_HIFI (for MP3 playback)142* 2. Set modifier to SND_USE_CASE_MOD_PLAY_TONE when incoming call happens.143* 3. Call snd_use_case_get("PlaybackPCM") to get ALSA PCM sink name for144* ringtone pcm data.145*/146#define SND_USE_CASE_MOD_CAPTURE_VOICE "Capture Voice" /**< Capture Voice Modifier */147#define SND_USE_CASE_MOD_CAPTURE_MUSIC "Capture Music" /**< Capture Music Modifier */148#define SND_USE_CASE_MOD_PLAY_MUSIC "Play Music" /**< Play Music Modifier */149#define SND_USE_CASE_MOD_PLAY_VOICE "Play Voice" /**< Play Voice Modifier */150#define SND_USE_CASE_MOD_PLAY_TONE "Play Tone" /**< Play Tone Modifier */151#define SND_USE_CASE_MOD_ECHO_REF "Echo Reference" /**< Echo Reference Modifier */152/* add new modifiers to end of list */153154155/**156* TQ - Tone Quality157*158* The interface allows clients to determine the audio TQ required for each159* use case verb and modifier. It's intended as an optional hint to the160* audio driver in order to lower power consumption.161*162*/163#define SND_USE_CASE_TQ_MUSIC "Music" /**< Music Tone Quality */164#define SND_USE_CASE_TQ_VOICE "Voice" /**< Voice Tone Quality */165#define SND_USE_CASE_TQ_TONES "Tones" /**< Tones Tone Quality */166167/** use case container */168typedef struct snd_use_case_mgr snd_use_case_mgr_t;169170/**171* \brief Create an identifier172* \param fmt Format (sprintf like)173* \param ... Optional arguments for sprintf like format174* \return Allocated string identifier or NULL on error175*/176char *snd_use_case_identifier(const char *fmt, ...);177178/**179* \brief Free a string list180* \param list The string list to free181* \param items Count of strings182* \return Zero if success, otherwise a negative error code183*/184int snd_use_case_free_list(const char *list[], int items);185186/**187* \brief Obtain a list of entries188* \param uc_mgr Use case manager (may be NULL - card list)189* \param identifier (may be NULL - card list)190* \param list Returned allocated list191* \return Number of list entries if success, otherwise a negative error code192*193* Defined identifiers:194* - NULL - get card list195* (in pair cardname+comment)196* - _verbs - get verb list197* (in pair verb+comment)198* - _devices[/{verb}] - get list of supported devices199* (in pair device+comment)200* - _modifiers[/{verb}] - get list of supported modifiers201* (in pair modifier+comment)202* - TQ[/{verb}] - get list of TQ identifiers203* - _enadevs - get list of enabled devices204* - _enamods - get list of enabled modifiers205*206* - _supporteddevs/{modifier}|{device}[/{verb}] - list of supported devices207* - _conflictingdevs/{modifier}|{device}[/{verb}] - list of conflicting devices208*209* Note that at most one of the supported/conflicting devs lists has210* any entries, and when neither is present, all devices are supported.211*212*/213int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr,214const char *identifier,215const char **list[]);216217218/**219* \brief Get current - string220* \param uc_mgr Use case manager221* \param identifier222* \param value Value pointer223* \return Zero if success, otherwise a negative error code224*225* Note: The returned string is dynamically allocated, use free() to226* deallocate this string. (Yes, the value parameter shouldn't be marked as227* "const", but it's too late to fix it, sorry about that.)228*229* Known identifiers:230* - NULL - return current card231* - _verb - return current verb232*233* - [=]{NAME}[/[{modifier}|{/device}][/{verb}]]234* - value identifier {NAME}235* - Search starts at given modifier or device if any,236* else at a verb237* - Search starts at given verb if any,238* else current verb239* - Searches modifier/device, then verb, then defaults240* - Specify a leading "=" to search only the exact241* device/modifier/verb specified, and not search242* through each object in turn.243* - Examples:244* - "PlaybackPCM/Play Music"245* - "CapturePCM/SPDIF"246* - From ValueDefaults only:247* "=Variable"248* - From current active verb:249* "=Variable//"250* - From verb "Verb":251* "=Variable//Verb"252* - From "Modifier" in current active verb:253* "=Variable/Modifier/"254* - From "Modifier" in "Verb":255* "=Variable/Modifier/Verb"256*257* Recommended names for values:258* - TQ259* - Tone Quality260* - PlaybackPCM261* - full PCM playback device name262* - PlaybackPCMIsDummy263* - Valid values: "yes" and "no". If set to "yes", the PCM named by the264* PlaybackPCM value is a dummy device, meaning that opening it enables265* an audio path in the hardware, but writing to the PCM device has no266* effect.267* - CapturePCM268* - full PCM capture device name269* - CapturePCMIsDummy270* - Valid values: "yes" and "no". If set to "yes", the PCM named by the271* CapturePCM value is a dummy device, meaning that opening it enables272* an audio path in the hardware, but reading from the PCM device has no273* effect.274* - PlaybackRate275* - playback device sample rate276* - PlaybackChannels277* - playback device channel count278* - PlaybackCTL279* - playback control device name280* - PlaybackVolume281* - playback control volume ID string282* - PlaybackSwitch283* - playback control switch ID string284* - CaptureRate285* - capture device sample rate286* - CaptureChannels287* - capture device channel count288* - CaptureCTL289* - capture control device name290* - CaptureVolume291* - capture control volume ID string292* - CaptureSwitch293* - capture control switch ID string294* - PlaybackMixer295* - name of playback mixer296* - PlaybackMixerID297* - mixer playback ID298* - CaptureMixer299* - name of capture mixer300* - CaptureMixerID301* - mixer capture ID302* - JackControl, JackDev, JackHWMute303* - Jack information for a device. The jack status can be reported via304* a kcontrol and/or via an input device. **JackControl** is the305* kcontrol name of the jack, and **JackDev** is the input device id of306* the jack (if the full input device path is /dev/input/by-id/foo, the307* JackDev value should be "foo"). UCM configuration files should308* contain both JackControl and JackDev when possible, because309* applications are likely to support only one or the other.310*311* If **JackHWMute** is set, it indicates that when the jack is plugged312* in, the hardware automatically mutes some other device(s). The313* JackHWMute value is a space-separated list of device names (this314* isn't compatible with device names with spaces in them, so don't use315* such device names!). Note that JackHWMute should be used only when316* the hardware enforces the automatic muting. If the hardware doesn't317* enforce any muting, it may still be tempting to set JackHWMute to318* trick upper software layers to e.g. automatically mute speakers when319* headphones are plugged in, but that's application policy320* configuration that doesn't belong to UCM configuration files.321*/322int snd_use_case_get(snd_use_case_mgr_t *uc_mgr,323const char *identifier,324const char **value);325326/**327* \brief Get current - integer328* \param uc_mgr Use case manager329* \param identifier330* \param value result331* \return Zero if success, otherwise a negative error code332*333* Known identifiers:334* - _devstatus/{device} - return status for given device335* - _modstatus/{modifier} - return status for given modifier336*/337int snd_use_case_geti(snd_use_case_mgr_t *uc_mgr,338const char *identifier,339long *value);340341/**342* \brief Set new343* \param uc_mgr Use case manager344* \param identifier345* \param value Value346* \return Zero if success, otherwise a negative error code347*348* Known identifiers:349* - _verb - set current verb = value350* - _enadev - enable given device = value351* - _disdev - disable given device = value352* - _swdev/{old_device} - new_device = value353* - disable old_device and then enable new_device354* - if old_device is not enabled just return355* - check transmit sequence firstly356* - _enamod - enable given modifier = value357* - _dismod - disable given modifier = value358* - _swmod/{old_modifier} - new_modifier = value359* - disable old_modifier and then enable new_modifier360* - if old_modifier is not enabled just return361* - check transmit sequence firstly362*/363int snd_use_case_set(snd_use_case_mgr_t *uc_mgr,364const char *identifier,365const char *value);366367/**368* \brief Open and initialise use case core for sound card369* \param uc_mgr Returned use case manager pointer370* \param card_name Sound card name.371* \return zero if success, otherwise a negative error code372*/373int snd_use_case_mgr_open(snd_use_case_mgr_t **uc_mgr, const char *card_name);374375376/**377* \brief Reload and re-parse use case configuration files for sound card.378* \param uc_mgr Use case manager379* \return zero if success, otherwise a negative error code380*/381int snd_use_case_mgr_reload(snd_use_case_mgr_t *uc_mgr);382383/**384* \brief Close use case manager385* \param uc_mgr Use case manager386* \return zero if success, otherwise a negative error code387*/388int snd_use_case_mgr_close(snd_use_case_mgr_t *uc_mgr);389390/**391* \brief Reset use case manager verb, device, modifier to deafult settings.392* \param uc_mgr Use case manager393* \return zero if success, otherwise a negative error code394*/395int snd_use_case_mgr_reset(snd_use_case_mgr_t *uc_mgr);396397/*398* helper functions399*/400401/**402* \brief Obtain a list of cards403* \param list Returned allocated list404* \return Number of list entries if success, otherwise a negative error code405*/406static __inline__ int snd_use_case_card_list(const char **list[])407{408return snd_use_case_get_list(NULL, NULL, list);409}410411/**412* \brief Obtain a list of verbs413* \param uc_mgr Use case manager414* \param list Returned list of verbs415* \return Number of list entries if success, otherwise a negative error code416*/417static __inline__ int snd_use_case_verb_list(snd_use_case_mgr_t *uc_mgr,418const char **list[])419{420return snd_use_case_get_list(uc_mgr, "_verbs", list);421}422423/**424* \}425*/426427#ifdef __cplusplus428}429#endif430431#endif /* __ALSA_USE_CASE_H */432433434