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