189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project/* 289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * 489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * you may not use this file except in compliance with the License. 689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * You may obtain a copy of the License at 789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * 889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * 1089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 1189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 1289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * See the License for the specific language governing permissions and 1489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * limitations under the License. 1589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project */ 1689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 1789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#ifndef ANDROID_AUDIOSYSTEM_H_ 1889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#define ANDROID_AUDIOSYSTEM_H_ 1989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 201ab85ec401801ef9a9184650d0f5a1639b45eeb9Glenn Kasten#include <hardware/audio_effect.h> 211ab85ec401801ef9a9184650d0f5a1639b45eeb9Glenn Kasten#include <media/IAudioFlingerClient.h> 2264760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h> 237394a4f358fa9908a9f0a7c954b65c399f4268e6Dima Zavin#include <system/audio_policy.h> 241ab85ec401801ef9a9184650d0f5a1639b45eeb9Glenn Kasten#include <utils/Errors.h> 251ab85ec401801ef9a9184650d0f5a1639b45eeb9Glenn Kasten#include <utils/Mutex.h> 26db5cb14318bb24cd6ea14ff7ceea0d5e1f83d903Dima Zavin 2789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectnamespace android { 2889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 2989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projecttypedef void (*audio_error_callback)(status_t err); 30c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 311ab85ec401801ef9a9184650d0f5a1639b45eeb9Glenn Kastenclass IAudioFlinger; 32c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentclass IAudioPolicyService; 33c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentclass String8; 3489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 3589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectclass AudioSystem 3689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{ 3789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectpublic: 3889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 3989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project /* These are static methods to control the system-wide AudioFlinger 4089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * only privileged processes can have access to them 4189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project */ 4289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 43c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // mute/unmute microphone 4489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static status_t muteMicrophone(bool state); 4589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static status_t isMicrophoneMuted(bool *state); 4689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 47c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // set/get master volume 4889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static status_t setMasterVolume(float value); 4989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static status_t getMasterVolume(float* volume); 504bcae82f9b07d1a39956c45a6f5bec0b696c4dd1Glenn Kasten 51c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // mute/unmute audio outputs 52c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static status_t setMasterMute(bool mute); 5389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static status_t getMasterMute(bool* mute); 5489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 55c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // set/get stream volume on specified output 5672ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten static status_t setStreamVolume(audio_stream_type_t stream, float value, 5772ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten audio_io_handle_t output); 5872ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten static status_t getStreamVolume(audio_stream_type_t stream, float* volume, 5972ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten audio_io_handle_t output); 60c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 61c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // mute/unmute stream 62fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten static status_t setStreamMute(audio_stream_type_t stream, bool mute); 63fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten static status_t getStreamMute(audio_stream_type_t stream, bool* mute); 6489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 65f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten // set audio mode in audio hardware 66f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten static status_t setMode(audio_mode_t mode); 6789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 68272ab546940054ad7991bef4b3a36f15175721cdJean-Michel Trivi // returns true in *state if tracks are active on the specified stream or have been active 69eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent // in the past inPastMs milliseconds 70fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten static status_t isStreamActive(audio_stream_type_t stream, bool *state, uint32_t inPastMs = 0); 71272ab546940054ad7991bef4b3a36f15175721cdJean-Michel Trivi // returns true in *state if tracks are active for what qualifies as remote playback 72272ab546940054ad7991bef4b3a36f15175721cdJean-Michel Trivi // on the specified stream or have been active in the past inPastMs milliseconds. Remote 73272ab546940054ad7991bef4b3a36f15175721cdJean-Michel Trivi // playback isn't mutually exclusive with local playback. 74272ab546940054ad7991bef4b3a36f15175721cdJean-Michel Trivi static status_t isStreamActiveRemotely(audio_stream_type_t stream, bool *state, 75272ab546940054ad7991bef4b3a36f15175721cdJean-Michel Trivi uint32_t inPastMs = 0); 76d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi // returns true in *state if a recorder is currently recording with the specified source 77d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi static status_t isSourceActive(audio_source_t source, bool *state); 7889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 79c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // set/get audio hardware parameters. The function accepts a list of parameters 80c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // key value pairs in the form: key1=value1;key2=value2;... 81c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // Some keys are reserved for standard parameters (See AudioParameter class). 82c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs); 83c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static String8 getParameters(audio_io_handle_t ioHandle, const String8& keys); 84c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 8589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static void setErrorCallback(audio_error_callback cb); 8689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 8789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project // helper function to obtain AudioFlinger service handle 8889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static const sp<IAudioFlinger>& get_audio_flinger(); 8989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 9089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static float linearToLog(int volume); 9189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static int logToLinear(float volume); 9289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 933b16c766d1ae2cfd8487e8ffb2b23936fc0a8e17Glenn Kasten static status_t getOutputSamplingRate(uint32_t* samplingRate, 9485ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten audio_stream_type_t stream = AUDIO_STREAM_DEFAULT); 95e33054eb968cbf8ccaee1b0ff0301403902deed6Glenn Kasten static status_t getOutputFrameCount(size_t* frameCount, 9685ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten audio_stream_type_t stream = AUDIO_STREAM_DEFAULT); 9785ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten static status_t getOutputLatency(uint32_t* latency, 9885ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten audio_stream_type_t stream = AUDIO_STREAM_DEFAULT); 991a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent static status_t getSamplingRate(audio_io_handle_t output, 1001a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent audio_stream_type_t streamType, 1013b16c766d1ae2cfd8487e8ffb2b23936fc0a8e17Glenn Kasten uint32_t* samplingRate); 1021a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent // returns the number of frames per audio HAL write buffer. Corresponds to 1031a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent // audio_stream->get_buffer_size()/audio_stream_frame_size() 1041a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent static status_t getFrameCount(audio_io_handle_t output, 1051a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent audio_stream_type_t stream, 106e33054eb968cbf8ccaee1b0ff0301403902deed6Glenn Kasten size_t* frameCount); 1071a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent // returns the audio output stream latency in ms. Corresponds to 1081a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent // audio_stream_out->get_latency() 1091a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent static status_t getLatency(audio_io_handle_t output, 1101a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent audio_stream_type_t stream, 1111a9ed11a472493cac7f6dfcbfac2064526a493edEric Laurent uint32_t* latency); 112c813985abd8ba61e999b3505f6a332574f87a1beAndreas Huber 113fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten static bool routedToA2dpOutput(audio_stream_type_t streamType); 114c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 115dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten static status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, 116dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten audio_channel_mask_t channelMask, size_t* buffSize); 11789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 118f0ee6f4055e26fb35d9c526a596668a4dc9da5baEric Laurent static status_t setVoiceVolume(float volume); 119c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 120342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent // return the number of audio frames written by AudioFlinger to audio HAL and 1214bcae82f9b07d1a39956c45a6f5bec0b696c4dd1Glenn Kasten // audio dsp to DAC since the output on which the specified stream is playing 122342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent // has exited standby. 123342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent // returned status (from utils/Errors.h) can be: 124342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data 125342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent // - INVALID_OPERATION: Not supported on current hardware platform 126342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent // - BAD_VALUE: invalid parameter 127342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent // NOTE: this feature is not supported on all hardware platforms and it is 128342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent // necessary to check returned status before using the returned values. 129ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald static status_t getRenderPosition(audio_io_handle_t output, 130ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald size_t *halFrames, 131ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald size_t *dspFrames, 132ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald audio_stream_type_t stream = AUDIO_STREAM_DEFAULT); 133342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent 134bf04a5d7f287fc712e0ed91849dc85c90c1e182dGlenn Kasten // return the number of input frames lost by HAL implementation, or 0 if the handle is invalid 135e33054eb968cbf8ccaee1b0ff0301403902deed6Glenn Kasten static size_t getInputFramesLost(audio_io_handle_t ioHandle); 136be916aa1267e2e6b1c148f51d11bcbbc79cb864cEric Laurent 137be916aa1267e2e6b1c148f51d11bcbbc79cb864cEric Laurent static int newAudioSessionId(); 1383a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen static void acquireAudioSessionId(int audioSession); 1393a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen static void releaseAudioSessionId(int audioSession); 140c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 141c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // types of io configuration change events received with ioConfigChanged() 142c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent enum io_config_event { 143c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent OUTPUT_OPENED, 144c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent OUTPUT_CLOSED, 145c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent OUTPUT_CONFIG_CHANGED, 146c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent INPUT_OPENED, 147c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent INPUT_CLOSED, 148c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent INPUT_CONFIG_CHANGED, 149c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent STREAM_CONFIG_CHANGED, 150c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent NUM_CONFIG_EVENTS 151c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent }; 152c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 15385ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten // audio output descriptor used to cache output configurations in client process to avoid 15485ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten // frequent calls through IAudioFlinger 155c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent class OutputDescriptor { 156c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent public: 157c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent OutputDescriptor() 158fad226abd12435dbcd232f7de396f1a097b2bd5fGlenn Kasten : samplingRate(0), format(AUDIO_FORMAT_DEFAULT), channelMask(0), frameCount(0), latency(0) {} 159c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 160c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent uint32_t samplingRate; 161eced2daaa6c91a3731eef978ce65c6ec319c5e6aGlenn Kasten audio_format_t format; 162fad226abd12435dbcd232f7de396f1a097b2bd5fGlenn Kasten audio_channel_mask_t channelMask; 163c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent size_t frameCount; 164c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent uint32_t latency; 165c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent }; 166c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 167a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent // Events used to synchronize actions between audio sessions. 16885ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten // For instance SYNC_EVENT_PRESENTATION_COMPLETE can be used to delay recording start until 16985ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten // playback is complete on another audio session. 170a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent // See definitions in MediaSyncEvent.java 171a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent enum sync_event_t { 172a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent SYNC_EVENT_SAME = -1, // used internally to indicate restart with same event 173a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent SYNC_EVENT_NONE = 0, 174a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent SYNC_EVENT_PRESENTATION_COMPLETE, 175a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent 176a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent // 177a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent // Define new events here: SYNC_EVENT_START, SYNC_EVENT_STOP, SYNC_EVENT_TIME ... 178a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent // 179a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent SYNC_EVENT_CNT, 180a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent }; 181a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent 1822986460984580833161bdaabc7f17da1005a8961Eric Laurent // Timeout for synchronous record start. Prevents from blocking the record thread forever 1832986460984580833161bdaabc7f17da1005a8961Eric Laurent // if the trigger event is not fired. 1842986460984580833161bdaabc7f17da1005a8961Eric Laurent static const uint32_t kSyncRecordStartTimeOutMs = 30000; 1852986460984580833161bdaabc7f17da1005a8961Eric Laurent 186c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // 187c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions) 188c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // 18985ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten static status_t setDeviceConnectionState(audio_devices_t device, audio_policy_dev_state_t state, 19085ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten const char *device_address); 19185ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten static audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device, 19285ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten const char *device_address); 193f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten static status_t setPhoneState(audio_mode_t state); 194fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin static status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config); 195fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin static audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage); 196fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin static audio_io_handle_t getOutput(audio_stream_type_t stream, 197c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent uint32_t samplingRate = 0, 19858f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten audio_format_t format = AUDIO_FORMAT_DEFAULT, 199254af180475346b6186b49c297f340c9c4817511Glenn Kasten audio_channel_mask_t channelMask = AUDIO_CHANNEL_OUT_STEREO, 200ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, 201ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald const audio_offload_info_t *offloadInfo = NULL); 202de070137f11d346fba77605bd76a44c040a618fcEric Laurent static status_t startOutput(audio_io_handle_t output, 203fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_stream_type_t stream, 204de070137f11d346fba77605bd76a44c040a618fcEric Laurent int session = 0); 205de070137f11d346fba77605bd76a44c040a618fcEric Laurent static status_t stopOutput(audio_io_handle_t output, 206fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_stream_type_t stream, 207de070137f11d346fba77605bd76a44c040a618fcEric Laurent int session = 0); 208c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static void releaseOutput(audio_io_handle_t output); 209eba51fb3a361f67a6a64d5a16eba6084fe27d60eGlenn Kasten static audio_io_handle_t getInput(audio_source_t inputSource, 210c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent uint32_t samplingRate = 0, 21158f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten audio_format_t format = AUDIO_FORMAT_DEFAULT, 212254af180475346b6186b49c297f340c9c4817511Glenn Kasten audio_channel_mask_t channelMask = AUDIO_CHANNEL_IN_MONO, 2137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int sessionId = 0); 214c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static status_t startInput(audio_io_handle_t input); 215c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static status_t stopInput(audio_io_handle_t input); 216c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static void releaseInput(audio_io_handle_t input); 217fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin static status_t initStreamVolume(audio_stream_type_t stream, 218c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent int indexMin, 219c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent int indexMax); 22083844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent static status_t setStreamVolumeIndex(audio_stream_type_t stream, 22183844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent int index, 22283844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent audio_devices_t device); 22383844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent static status_t getStreamVolumeIndex(audio_stream_type_t stream, 22483844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent int *index, 22583844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent audio_devices_t device); 226c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 227fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin static uint32_t getStrategyForStream(audio_stream_type_t stream); 2286374252107fd6539397598195ea6defd5870fafbEric Laurent static audio_devices_t getDevicesForStream(audio_stream_type_t stream); 229de070137f11d346fba77605bd76a44c040a618fcEric Laurent 23058e5aa34f01d663654d8bafad65db1dda42161ffGlenn Kasten static audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc); 23158e5aa34f01d663654d8bafad65db1dda42161ffGlenn Kasten static status_t registerEffect(const effect_descriptor_t *desc, 2327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent audio_io_handle_t io, 233de070137f11d346fba77605bd76a44c040a618fcEric Laurent uint32_t strategy, 234de070137f11d346fba77605bd76a44c040a618fcEric Laurent int session, 235de070137f11d346fba77605bd76a44c040a618fcEric Laurent int id); 236de070137f11d346fba77605bd76a44c040a618fcEric Laurent static status_t unregisterEffect(int id); 237db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent static status_t setEffectEnabled(int id, bool enabled); 238de070137f11d346fba77605bd76a44c040a618fcEric Laurent 2399f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent // clear stream to output mapping cache (gStreamOutputMap) 2409f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent // and output configuration cache (gOutputs) 2419f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent static void clearAudioConfigCache(); 2429f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent 243c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static const sp<IAudioPolicyService>& get_audio_policy_service(); 244c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 245cc0f1cfb69ce8b8985fc2c0984847a06a13ad22dGlenn Kasten // helpers for android.media.AudioManager.getProperty(), see description there for meaning 2463b16c766d1ae2cfd8487e8ffb2b23936fc0a8e17Glenn Kasten static uint32_t getPrimaryOutputSamplingRate(); 247e33054eb968cbf8ccaee1b0ff0301403902deed6Glenn Kasten static size_t getPrimaryOutputFrameCount(); 248cc0f1cfb69ce8b8985fc2c0984847a06a13ad22dGlenn Kasten 2494182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten static status_t setLowRamDevice(bool isLowRamDevice); 2504182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten 251ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald // Check if hw offload is possible for given format, stream type, sample rate, 252ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald // bit rate, duration, video and streaming or offload property is enabled 253ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald static bool isOffloadSupported(const audio_offload_info_t& info); 254ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald 25546291616486979986cba3ab83e894728ef53063fEric Laurent // check presence of audio flinger service. 25646291616486979986cba3ab83e894728ef53063fEric Laurent // returns NO_ERROR if binding to service succeeds, DEAD_OBJECT otherwise 25746291616486979986cba3ab83e894728ef53063fEric Laurent static status_t checkAudioFlinger(); 25889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project // ---------------------------------------------------------------------------- 25989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 26089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectprivate: 26189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 26289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient 26389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project { 26489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project public: 265c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent AudioFlingerClient() { 26689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project } 267c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 26889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project // DeathRecipient 26989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project virtual void binderDied(const wp<IBinder>& who); 270c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 27189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project // IAudioFlingerClient 272c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 273c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // indicate a change in the configuration of an output or input: keeps the cached 274b81cc8c6f3eec9edb255ea99b6a6f243585b1e38Glenn Kasten // values for output/input parameters up-to-date in client process 275b81cc8c6f3eec9edb255ea99b6a6f243585b1e38Glenn Kasten virtual void ioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2); 27689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project }; 27789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 278c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent class AudioPolicyServiceClient: public IBinder::DeathRecipient 279c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent { 280c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent public: 281c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent AudioPolicyServiceClient() { 282c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent } 28389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 284c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // DeathRecipient 285c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent virtual void binderDied(const wp<IBinder>& who); 286c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent }; 287c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 288c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static sp<AudioFlingerClient> gAudioFlingerClient; 289c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient; 29089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project friend class AudioFlingerClient; 291c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent friend class AudioPolicyServiceClient; 29289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 29389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static Mutex gLock; 29489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static sp<IAudioFlinger> gAudioFlinger; 29589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static audio_error_callback gAudioErrorCallback; 296c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 29789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static size_t gInBuffSize; 29889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project // previous parameters for recording buffer size queries 29989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project static uint32_t gPrevInSamplingRate; 30058f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten static audio_format_t gPrevInFormat; 301dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten static audio_channel_mask_t gPrevInChannelMask; 30289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 303c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static sp<IAudioPolicyService> gAudioPolicyService; 304c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 305c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent // mapping between stream types and outputs 306211eeaf17e5565b68447d29799dbf158a33cf4cfGlenn Kasten static DefaultKeyedVector<audio_stream_type_t, audio_io_handle_t> gStreamOutputMap; 3079f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent // list of output descriptors containing cached parameters 3089f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent // (sampling rate, framecount, channel count...) 309c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs; 310c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent}; 311c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent 31289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}; // namespace android 31389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project 31489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#endif /*ANDROID_AUDIOSYSTEM_H_*/ 315