1 /* 2 * Copyright (C) 2007 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_IAUDIOFLINGER_H 18 #define ANDROID_IAUDIOFLINGER_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 #include <unistd.h> 23 24 #include <utils/RefBase.h> 25 #include <utils/Errors.h> 26 #include <binder/IInterface.h> 27 #include <media/IAudioTrack.h> 28 #include <media/IAudioRecord.h> 29 #include <media/IAudioFlingerClient.h> 30 #include <system/audio.h> 31 #include <system/audio_effect.h> 32 #include <system/audio_policy.h> 33 #include <media/IEffect.h> 34 #include <media/IEffectClient.h> 35 #include <utils/String8.h> 36 37 namespace android { 38 39 // ---------------------------------------------------------------------------- 40 41 class IAudioFlinger : public IInterface 42 { 43 public: 44 DECLARE_META_INTERFACE(AudioFlinger); 45 46 47 // invariant on exit for all APIs that return an sp<>: 48 // (return value != 0) == (*status == NO_ERROR) 49 50 /* create an audio track and registers it with AudioFlinger. 51 * return null if the track cannot be created. 52 */ 53 virtual sp<IAudioTrack> createTrack( 54 audio_stream_type_t streamType, 55 uint32_t sampleRate, 56 audio_format_t format, 57 audio_channel_mask_t channelMask, 58 size_t *pFrameCount, 59 audio_output_flags_t *flags, 60 const sp<IMemory>& sharedBuffer, 61 // On successful return, AudioFlinger takes over the handle 62 // reference and will release it when the track is destroyed. 63 // However on failure, the client is responsible for release. 64 audio_io_handle_t output, 65 pid_t pid, 66 pid_t tid, // -1 means unused, otherwise must be valid non-0 67 audio_session_t *sessionId, 68 int clientUid, 69 status_t *status, 70 audio_port_handle_t portId) = 0; 71 72 virtual sp<IAudioRecord> openRecord( 73 // On successful return, AudioFlinger takes over the handle 74 // reference and will release it when the track is destroyed. 75 // However on failure, the client is responsible for release. 76 audio_io_handle_t input, 77 uint32_t sampleRate, 78 audio_format_t format, 79 audio_channel_mask_t channelMask, 80 const String16& callingPackage, 81 size_t *pFrameCount, 82 audio_input_flags_t *flags, 83 pid_t pid, 84 pid_t tid, // -1 means unused, otherwise must be valid non-0 85 int clientUid, 86 audio_session_t *sessionId, 87 size_t *notificationFrames, 88 sp<IMemory>& cblk, 89 sp<IMemory>& buffers, // return value 0 means it follows cblk 90 status_t *status, 91 audio_port_handle_t portId) = 0; 92 93 // FIXME Surprisingly, format/latency don't work for input handles 94 95 /* query the audio hardware state. This state never changes, 96 * and therefore can be cached. 97 */ 98 virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const = 0; 99 100 // reserved; formerly channelCount() 101 102 virtual audio_format_t format(audio_io_handle_t output) const = 0; 103 virtual size_t frameCount(audio_io_handle_t ioHandle) const = 0; 104 105 // return estimated latency in milliseconds 106 virtual uint32_t latency(audio_io_handle_t output) const = 0; 107 108 /* set/get the audio hardware state. This will probably be used by 109 * the preference panel, mostly. 110 */ 111 virtual status_t setMasterVolume(float value) = 0; 112 virtual status_t setMasterMute(bool muted) = 0; 113 114 virtual float masterVolume() const = 0; 115 virtual bool masterMute() const = 0; 116 117 /* set/get stream type state. This will probably be used by 118 * the preference panel, mostly. 119 */ 120 virtual status_t setStreamVolume(audio_stream_type_t stream, float value, 121 audio_io_handle_t output) = 0; 122 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0; 123 124 virtual float streamVolume(audio_stream_type_t stream, 125 audio_io_handle_t output) const = 0; 126 virtual bool streamMute(audio_stream_type_t stream) const = 0; 127 128 // set audio mode 129 virtual status_t setMode(audio_mode_t mode) = 0; 130 131 // mic mute/state 132 virtual status_t setMicMute(bool state) = 0; 133 virtual bool getMicMute() const = 0; 134 135 virtual status_t setParameters(audio_io_handle_t ioHandle, 136 const String8& keyValuePairs) = 0; 137 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) 138 const = 0; 139 140 // Register an object to receive audio input/output change and track notifications. 141 // For a given calling pid, AudioFlinger disregards any registrations after the first. 142 // Thus the IAudioFlingerClient must be a singleton per process. 143 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0; 144 145 // retrieve the audio recording buffer size 146 // FIXME This API assumes a route, and so should be deprecated. 147 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, 148 audio_channel_mask_t channelMask) const = 0; 149 150 virtual status_t openOutput(audio_module_handle_t module, 151 audio_io_handle_t *output, 152 audio_config_t *config, 153 audio_devices_t *devices, 154 const String8& address, 155 uint32_t *latencyMs, 156 audio_output_flags_t flags) = 0; 157 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, 158 audio_io_handle_t output2) = 0; 159 virtual status_t closeOutput(audio_io_handle_t output) = 0; 160 virtual status_t suspendOutput(audio_io_handle_t output) = 0; 161 virtual status_t restoreOutput(audio_io_handle_t output) = 0; 162 163 virtual status_t openInput(audio_module_handle_t module, 164 audio_io_handle_t *input, 165 audio_config_t *config, 166 audio_devices_t *device, 167 const String8& address, 168 audio_source_t source, 169 audio_input_flags_t flags) = 0; 170 virtual status_t closeInput(audio_io_handle_t input) = 0; 171 172 virtual status_t invalidateStream(audio_stream_type_t stream) = 0; 173 174 virtual status_t setVoiceVolume(float volume) = 0; 175 176 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, 177 audio_io_handle_t output) const = 0; 178 179 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0; 180 181 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use) = 0; 182 183 virtual void acquireAudioSessionId(audio_session_t audioSession, pid_t pid) = 0; 184 virtual void releaseAudioSessionId(audio_session_t audioSession, pid_t pid) = 0; 185 186 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0; 187 188 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0; 189 190 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID, 191 effect_descriptor_t *pDescriptor) const = 0; 192 193 virtual sp<IEffect> createEffect( 194 effect_descriptor_t *pDesc, 195 const sp<IEffectClient>& client, 196 int32_t priority, 197 // AudioFlinger doesn't take over handle reference from client 198 audio_io_handle_t output, 199 audio_session_t sessionId, 200 const String16& callingPackage, 201 pid_t pid, 202 status_t *status, 203 int *id, 204 int *enabled) = 0; 205 206 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput, 207 audio_io_handle_t dstOutput) = 0; 208 209 virtual audio_module_handle_t loadHwModule(const char *name) = 0; 210 211 // helpers for android.media.AudioManager.getProperty(), see description there for meaning 212 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation 213 // that looks on primary device for a stream with fast flag, primary flag, or first one. 214 virtual uint32_t getPrimaryOutputSamplingRate() = 0; 215 virtual size_t getPrimaryOutputFrameCount() = 0; 216 217 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute, 218 // and should be called at most once. For a definition of what "low RAM" means, see 219 // android.app.ActivityManager.isLowRamDevice(). 220 virtual status_t setLowRamDevice(bool isLowRamDevice) = 0; 221 222 /* List available audio ports and their attributes */ 223 virtual status_t listAudioPorts(unsigned int *num_ports, 224 struct audio_port *ports) = 0; 225 226 /* Get attributes for a given audio port */ 227 virtual status_t getAudioPort(struct audio_port *port) = 0; 228 229 /* Create an audio patch between several source and sink ports */ 230 virtual status_t createAudioPatch(const struct audio_patch *patch, 231 audio_patch_handle_t *handle) = 0; 232 233 /* Release an audio patch */ 234 virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0; 235 236 /* List existing audio patches */ 237 virtual status_t listAudioPatches(unsigned int *num_patches, 238 struct audio_patch *patches) = 0; 239 /* Set audio port configuration */ 240 virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0; 241 242 /* Get the HW synchronization source used for an audio session */ 243 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId) = 0; 244 245 /* Indicate JAVA services are ready (scheduling, power management ...) */ 246 virtual status_t systemReady() = 0; 247 248 // Returns the number of frames per audio HAL buffer. 249 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const = 0; 250 }; 251 252 253 // ---------------------------------------------------------------------------- 254 255 class BnAudioFlinger : public BnInterface<IAudioFlinger> 256 { 257 public: 258 virtual status_t onTransact( uint32_t code, 259 const Parcel& data, 260 Parcel* reply, 261 uint32_t flags = 0); 262 263 // Requests media.log to start merging log buffers 264 virtual void requestLogMerge() = 0; 265 }; 266 267 // ---------------------------------------------------------------------------- 268 269 }; // namespace android 270 271 #endif // ANDROID_IAUDIOFLINGER_H 272