AudioPolicyInterface.h revision baac183f3808d7b68f184647a97bd381620415fe
1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ANDROID_AUDIOPOLICY_INTERFACE_H 18#define ANDROID_AUDIOPOLICY_INTERFACE_H 19 20#include <media/AudioSystem.h> 21#include <media/AudioPolicy.h> 22#include <utils/String8.h> 23 24#include <hardware/audio_policy.h> 25 26namespace android { 27 28// ---------------------------------------------------------------------------- 29 30// The AudioPolicyInterface and AudioPolicyClientInterface classes define the communication interfaces 31// between the platform specific audio policy manager and Android generic audio policy manager. 32// The platform specific audio policy manager must implement methods of the AudioPolicyInterface class. 33// This implementation makes use of the AudioPolicyClientInterface to control the activity and 34// configuration of audio input and output streams. 35// 36// The platform specific audio policy manager is in charge of the audio routing and volume control 37// policies for a given platform. 38// The main roles of this module are: 39// - keep track of current system state (removable device connections, phone state, user requests...). 40// System state changes and user actions are notified to audio policy manager with methods of the AudioPolicyInterface. 41// - process getOutput() queries received when AudioTrack objects are created: Those queries 42// return a handler on an output that has been selected, configured and opened by the audio policy manager and that 43// must be used by the AudioTrack when registering to the AudioFlinger with the createTrack() method. 44// When the AudioTrack object is released, a putOutput() query is received and the audio policy manager can decide 45// to close or reconfigure the output depending on other streams using this output and current system state. 46// - similarly process getInput() and putInput() queries received from AudioRecord objects and configure audio inputs. 47// - process volume control requests: the stream volume is converted from an index value (received from UI) to a float value 48// applicable to each output as a function of platform specific settings and current output route (destination device). It 49// also make sure that streams are not muted if not allowed (e.g. camera shutter sound in some countries). 50// 51// The platform specific audio policy manager is provided as a shared library by platform vendors (as for libaudio.so) 52// and is linked with libaudioflinger.so 53 54 55// Audio Policy Manager Interface 56class AudioPolicyInterface 57{ 58 59public: 60 virtual ~AudioPolicyInterface() {} 61 // 62 // configuration functions 63 // 64 65 // indicate a change in device connection status 66 virtual status_t setDeviceConnectionState(audio_devices_t device, 67 audio_policy_dev_state_t state, 68 const char *device_address) = 0; 69 // retrieve a device connection status 70 virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device, 71 const char *device_address) = 0; 72 // indicate a change in phone state. Valid phones states are defined by audio_mode_t 73 virtual void setPhoneState(audio_mode_t state) = 0; 74 // force using a specific device category for the specified usage 75 virtual void setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) = 0; 76 // retrieve current device category forced for a given usage 77 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) = 0; 78 // set a system property (e.g. camera sound always audible) 79 virtual void setSystemProperty(const char* property, const char* value) = 0; 80 // check proper initialization 81 virtual status_t initCheck() = 0; 82 83 // 84 // Audio routing query functions 85 // 86 87 // request an output appropriate for playback of the supplied stream type and parameters 88 virtual audio_io_handle_t getOutput(audio_stream_type_t stream, 89 uint32_t samplingRate, 90 audio_format_t format, 91 audio_channel_mask_t channelMask, 92 audio_output_flags_t flags, 93 const audio_offload_info_t *offloadInfo) = 0; 94 virtual status_t getOutputForAttr(const audio_attributes_t *attr, 95 audio_io_handle_t *output, 96 audio_session_t session, 97 audio_stream_type_t *stream, 98 uint32_t samplingRate, 99 audio_format_t format, 100 audio_channel_mask_t channelMask, 101 audio_output_flags_t flags, 102 const audio_offload_info_t *offloadInfo) = 0; 103 // indicates to the audio policy manager that the output starts being used by corresponding stream. 104 virtual status_t startOutput(audio_io_handle_t output, 105 audio_stream_type_t stream, 106 audio_session_t session) = 0; 107 // indicates to the audio policy manager that the output stops being used by corresponding stream. 108 virtual status_t stopOutput(audio_io_handle_t output, 109 audio_stream_type_t stream, 110 audio_session_t session) = 0; 111 // releases the output. 112 virtual void releaseOutput(audio_io_handle_t output, 113 audio_stream_type_t stream, 114 audio_session_t session) = 0; 115 116 // request an input appropriate for record from the supplied device with supplied parameters. 117 virtual status_t getInputForAttr(const audio_attributes_t *attr, 118 audio_io_handle_t *input, 119 audio_session_t session, 120 uint32_t samplingRate, 121 audio_format_t format, 122 audio_channel_mask_t channelMask, 123 audio_input_flags_t flags) = 0; 124 // indicates to the audio policy manager that the input starts being used. 125 virtual status_t startInput(audio_io_handle_t input, 126 audio_session_t session) = 0; 127 // indicates to the audio policy manager that the input stops being used. 128 virtual status_t stopInput(audio_io_handle_t input, 129 audio_session_t session) = 0; 130 // releases the input. 131 virtual void releaseInput(audio_io_handle_t input, 132 audio_session_t session) = 0; 133 134 // 135 // volume control functions 136 // 137 138 // initialises stream volume conversion parameters by specifying volume index range. 139 virtual void initStreamVolume(audio_stream_type_t stream, 140 int indexMin, 141 int indexMax) = 0; 142 143 // sets the new stream volume at a level corresponding to the supplied index for the 144 // supplied device. By convention, specifying AUDIO_DEVICE_OUT_DEFAULT means 145 // setting volume for all devices 146 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, 147 int index, 148 audio_devices_t device) = 0; 149 150 // retrieve current volume index for the specified stream and the 151 // specified device. By convention, specifying AUDIO_DEVICE_OUT_DEFAULT means 152 // querying the volume of the active device. 153 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, 154 int *index, 155 audio_devices_t device) = 0; 156 157 // return the strategy corresponding to a given stream type 158 virtual uint32_t getStrategyForStream(audio_stream_type_t stream) = 0; 159 160 // return the enabled output devices for the given stream type 161 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0; 162 163 // Audio effect management 164 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0; 165 virtual status_t registerEffect(const effect_descriptor_t *desc, 166 audio_io_handle_t io, 167 uint32_t strategy, 168 int session, 169 int id) = 0; 170 virtual status_t unregisterEffect(int id) = 0; 171 virtual status_t setEffectEnabled(int id, bool enabled) = 0; 172 173 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const = 0; 174 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, 175 uint32_t inPastMs = 0) const = 0; 176 virtual bool isSourceActive(audio_source_t source) const = 0; 177 178 //dump state 179 virtual status_t dump(int fd) = 0; 180 181 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo) = 0; 182 183 virtual status_t listAudioPorts(audio_port_role_t role, 184 audio_port_type_t type, 185 unsigned int *num_ports, 186 struct audio_port *ports, 187 unsigned int *generation) = 0; 188 virtual status_t getAudioPort(struct audio_port *port) = 0; 189 virtual status_t createAudioPatch(const struct audio_patch *patch, 190 audio_patch_handle_t *handle, 191 uid_t uid) = 0; 192 virtual status_t releaseAudioPatch(audio_patch_handle_t handle, 193 uid_t uid) = 0; 194 virtual status_t listAudioPatches(unsigned int *num_patches, 195 struct audio_patch *patches, 196 unsigned int *generation) = 0; 197 virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0; 198 virtual void clearAudioPatches(uid_t uid) = 0; 199 200 virtual status_t acquireSoundTriggerSession(audio_session_t *session, 201 audio_io_handle_t *ioHandle, 202 audio_devices_t *device) = 0; 203 204 virtual status_t releaseSoundTriggerSession(audio_session_t session) = 0; 205 206 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes) = 0; 207 virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes) = 0; 208}; 209 210 211// Audio Policy client Interface 212class AudioPolicyClientInterface 213{ 214public: 215 virtual ~AudioPolicyClientInterface() {} 216 217 // 218 // Audio HW module functions 219 // 220 221 // loads a HW module. 222 virtual audio_module_handle_t loadHwModule(const char *name) = 0; 223 224 // 225 // Audio output Control functions 226 // 227 228 // opens an audio output with the requested parameters. The parameter values can indicate to use the default values 229 // in case the audio policy manager has no specific requirements for the output being opened. 230 // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream. 231 // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly. 232 virtual status_t openOutput(audio_module_handle_t module, 233 audio_io_handle_t *output, 234 audio_config_t *config, 235 audio_devices_t *devices, 236 const String8& address, 237 uint32_t *latencyMs, 238 audio_output_flags_t flags) = 0; 239 // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by 240 // a special mixer thread in the AudioFlinger. 241 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2) = 0; 242 // closes the output stream 243 virtual status_t closeOutput(audio_io_handle_t output) = 0; 244 // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in 245 // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded. 246 virtual status_t suspendOutput(audio_io_handle_t output) = 0; 247 // restores a suspended output. 248 virtual status_t restoreOutput(audio_io_handle_t output) = 0; 249 250 // 251 // Audio input Control functions 252 // 253 254 // opens an audio input 255 virtual status_t openInput(audio_module_handle_t module, 256 audio_io_handle_t *input, 257 audio_config_t *config, 258 audio_devices_t *device, 259 const String8& address, 260 audio_source_t source, 261 audio_input_flags_t flags) = 0; 262 // closes an audio input 263 virtual status_t closeInput(audio_io_handle_t input) = 0; 264 // 265 // misc control functions 266 // 267 268 // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes 269 // for each output (destination device) it is attached to. 270 virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0) = 0; 271 272 // invalidate a stream type, causing a reroute to an unspecified new output 273 virtual status_t invalidateStream(audio_stream_type_t stream) = 0; 274 275 // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface. 276 virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0) = 0; 277 // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager. 278 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) = 0; 279 280 // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing 281 // over a telephony device during a phone call. 282 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream) = 0; 283 virtual status_t stopTone() = 0; 284 285 // set down link audio volume. 286 virtual status_t setVoiceVolume(float volume, int delayMs = 0) = 0; 287 288 // move effect to the specified output 289 virtual status_t moveEffects(int session, 290 audio_io_handle_t srcOutput, 291 audio_io_handle_t dstOutput) = 0; 292 293 /* Create a patch between several source and sink ports */ 294 virtual status_t createAudioPatch(const struct audio_patch *patch, 295 audio_patch_handle_t *handle, 296 int delayMs) = 0; 297 298 /* Release a patch */ 299 virtual status_t releaseAudioPatch(audio_patch_handle_t handle, 300 int delayMs) = 0; 301 302 /* Set audio port configuration */ 303 virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs) = 0; 304 305 virtual void onAudioPortListUpdate() = 0; 306 307 virtual void onAudioPatchListUpdate() = 0; 308 309 virtual audio_unique_id_t newAudioUniqueId() = 0; 310}; 311 312extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface); 313extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface); 314 315 316}; // namespace android 317 318#endif // ANDROID_AUDIOPOLICY_INTERFACE_H 319