IAudioFlinger.h revision 4b123406c10c17852734a1b691bb9ce2a4cb7caf
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 }; 54 typedef uint32_t track_flags_t; 55 56 // invariant on exit for all APIs that return an sp<>: 57 // (return value != 0) == (*status == NO_ERROR) 58 59 /* create an audio track and registers it with AudioFlinger. 60 * return null if the track cannot be created. 61 */ 62 virtual sp<IAudioTrack> createTrack( 63 audio_stream_type_t streamType, 64 uint32_t sampleRate, 65 audio_format_t format, 66 audio_channel_mask_t channelMask, 67 size_t *pFrameCount, 68 track_flags_t *flags, 69 const sp<IMemory>& sharedBuffer, 70 // On successful return, AudioFlinger takes over the handle 71 // reference and will release it when the track is destroyed. 72 // However on failure, the client is responsible for release. 73 audio_io_handle_t output, 74 pid_t tid, // -1 means unused, otherwise must be valid non-0 75 int *sessionId, 76 int clientUid, 77 status_t *status) = 0; 78 79 virtual sp<IAudioRecord> openRecord( 80 // On successful return, AudioFlinger takes over the handle 81 // reference and will release it when the track is destroyed. 82 // However on failure, the client is responsible for release. 83 audio_io_handle_t input, 84 uint32_t sampleRate, 85 audio_format_t format, 86 audio_channel_mask_t channelMask, 87 size_t *pFrameCount, 88 track_flags_t *flags, 89 pid_t tid, // -1 means unused, otherwise must be valid non-0 90 int *sessionId, 91 sp<IMemory>& cblk, 92 sp<IMemory>& buffers, // return value 0 means it follows cblk 93 status_t *status) = 0; 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 output) const = 0; 99#if 0 100 virtual int channelCount(audio_io_handle_t output) const = 0; 101#endif 102 virtual audio_format_t format(audio_io_handle_t output) const = 0; 103 virtual size_t frameCount(audio_io_handle_t output) 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 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, 147 audio_channel_mask_t channelMask) const = 0; 148 149 virtual audio_io_handle_t openOutput(audio_module_handle_t module, 150 audio_devices_t *pDevices, 151 uint32_t *pSamplingRate, 152 audio_format_t *pFormat, 153 audio_channel_mask_t *pChannelMask, 154 uint32_t *pLatencyMs, 155 audio_output_flags_t flags, 156 const audio_offload_info_t *offloadInfo = NULL) = 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 audio_io_handle_t openInput(audio_module_handle_t module, 164 audio_devices_t *pDevices, 165 uint32_t *pSamplingRate, 166 audio_format_t *pFormat, 167 audio_channel_mask_t *pChannelMask) = 0; 168 virtual status_t closeInput(audio_io_handle_t input) = 0; 169 170 virtual status_t invalidateStream(audio_stream_type_t stream) = 0; 171 172 virtual status_t setVoiceVolume(float volume) = 0; 173 174 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, 175 audio_io_handle_t output) const = 0; 176 177 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0; 178 179 virtual int newAudioSessionId() = 0; 180 181 virtual void acquireAudioSessionId(int audioSession, pid_t pid) = 0; 182 virtual void releaseAudioSessionId(int audioSession, pid_t pid) = 0; 183 184 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0; 185 186 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0; 187 188 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID, 189 effect_descriptor_t *pDescriptor) const = 0; 190 191 virtual sp<IEffect> createEffect( 192 effect_descriptor_t *pDesc, 193 const sp<IEffectClient>& client, 194 int32_t priority, 195 // AudioFlinger doesn't take over handle reference from client 196 audio_io_handle_t output, 197 int sessionId, 198 status_t *status, 199 int *id, 200 int *enabled) = 0; 201 202 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput, 203 audio_io_handle_t dstOutput) = 0; 204 205 virtual audio_module_handle_t loadHwModule(const char *name) = 0; 206 207 // helpers for android.media.AudioManager.getProperty(), see description there for meaning 208 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation 209 // that looks on primary device for a stream with fast flag, primary flag, or first one. 210 virtual uint32_t getPrimaryOutputSamplingRate() = 0; 211 virtual size_t getPrimaryOutputFrameCount() = 0; 212 213 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute, 214 // and should be called at most once. For a definition of what "low RAM" means, see 215 // android.app.ActivityManager.isLowRamDevice(). 216 virtual status_t setLowRamDevice(bool isLowRamDevice) = 0; 217 218 /* List available audio ports and their attributes */ 219 virtual status_t listAudioPorts(unsigned int *num_ports, 220 struct audio_port *ports) = 0; 221 222 /* Get attributes for a given audio port */ 223 virtual status_t getAudioPort(struct audio_port *port) = 0; 224 225 /* Create an audio patch between several source and sink ports */ 226 virtual status_t createAudioPatch(const struct audio_patch *patch, 227 audio_patch_handle_t *handle) = 0; 228 229 /* Release an audio patch */ 230 virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0; 231 232 /* List existing audio patches */ 233 virtual status_t listAudioPatches(unsigned int *num_patches, 234 struct audio_patch *patches) = 0; 235 /* Set audio port configuration */ 236 virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0; 237 238}; 239 240 241// ---------------------------------------------------------------------------- 242 243class BnAudioFlinger : public BnInterface<IAudioFlinger> 244{ 245public: 246 virtual status_t onTransact( uint32_t code, 247 const Parcel& data, 248 Parcel* reply, 249 uint32_t flags = 0); 250}; 251 252// ---------------------------------------------------------------------------- 253 254}; // namespace android 255 256#endif // ANDROID_IAUDIOFLINGER_H 257