IAudioFlinger.h revision d054c32443a493513ab63529b0c8b1aca290278c
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 /* create an audio track and registers it with AudioFlinger. 57 * return null if the track cannot be created. 58 */ 59 virtual sp<IAudioTrack> createTrack( 60 audio_stream_type_t streamType, 61 uint32_t sampleRate, 62 audio_format_t format, 63 audio_channel_mask_t channelMask, 64 size_t frameCount, 65 track_flags_t *flags, 66 const sp<IMemory>& sharedBuffer, 67 audio_io_handle_t output, 68 pid_t tid, // -1 means unused, otherwise must be valid non-0 69 int *sessionId, 70 // input: ignored 71 // output: server's description of IAudioTrack for display in logs. 72 // Don't attempt to parse, as the format could change. 73 String8& name, 74 status_t *status) = 0; 75 76 virtual sp<IAudioRecord> openRecord( 77 audio_io_handle_t input, 78 uint32_t sampleRate, 79 audio_format_t format, 80 audio_channel_mask_t channelMask, 81 size_t frameCount, 82 track_flags_t flags, 83 pid_t tid, // -1 means unused, otherwise must be valid non-0 84 int *sessionId, 85 status_t *status) = 0; 86 87 /* query the audio hardware state. This state never changes, 88 * and therefore can be cached. 89 */ 90 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0; 91#if 0 92 virtual int channelCount(audio_io_handle_t output) const = 0; 93#endif 94 virtual audio_format_t format(audio_io_handle_t output) const = 0; 95 virtual size_t frameCount(audio_io_handle_t output) const = 0; 96 97 // return estimated latency in milliseconds 98 virtual uint32_t latency(audio_io_handle_t output) const = 0; 99 100 /* set/get the audio hardware state. This will probably be used by 101 * the preference panel, mostly. 102 */ 103 virtual status_t setMasterVolume(float value) = 0; 104 virtual status_t setMasterMute(bool muted) = 0; 105 106 virtual float masterVolume() const = 0; 107 virtual bool masterMute() const = 0; 108 109 /* set/get stream type state. This will probably be used by 110 * the preference panel, mostly. 111 */ 112 virtual status_t setStreamVolume(audio_stream_type_t stream, float value, 113 audio_io_handle_t output) = 0; 114 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0; 115 116 virtual float streamVolume(audio_stream_type_t stream, 117 audio_io_handle_t output) const = 0; 118 virtual bool streamMute(audio_stream_type_t stream) const = 0; 119 120 // set audio mode 121 virtual status_t setMode(audio_mode_t mode) = 0; 122 123 // mic mute/state 124 virtual status_t setMicMute(bool state) = 0; 125 virtual bool getMicMute() const = 0; 126 127 virtual status_t setParameters(audio_io_handle_t ioHandle, 128 const String8& keyValuePairs) = 0; 129 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) 130 const = 0; 131 132 // Register an object to receive audio input/output change and track notifications. 133 // For a given calling pid, AudioFlinger disregards any registrations after the first. 134 // Thus the IAudioFlingerClient must be a singleton per process. 135 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0; 136 137 // retrieve the audio recording buffer size 138 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, 139 audio_channel_mask_t channelMask) const = 0; 140 141 virtual audio_io_handle_t openOutput(audio_module_handle_t module, 142 audio_devices_t *pDevices, 143 uint32_t *pSamplingRate, 144 audio_format_t *pFormat, 145 audio_channel_mask_t *pChannelMask, 146 uint32_t *pLatencyMs, 147 audio_output_flags_t flags, 148 const audio_offload_info_t *offloadInfo = NULL) = 0; 149 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, 150 audio_io_handle_t output2) = 0; 151 virtual status_t closeOutput(audio_io_handle_t output) = 0; 152 virtual status_t suspendOutput(audio_io_handle_t output) = 0; 153 virtual status_t restoreOutput(audio_io_handle_t output) = 0; 154 155 virtual audio_io_handle_t openInput(audio_module_handle_t module, 156 audio_devices_t *pDevices, 157 uint32_t *pSamplingRate, 158 audio_format_t *pFormat, 159 audio_channel_mask_t *pChannelMask) = 0; 160 virtual status_t closeInput(audio_io_handle_t input) = 0; 161 162 virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0; 163 164 virtual status_t setVoiceVolume(float volume) = 0; 165 166 virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames, 167 audio_io_handle_t output) const = 0; 168 169 virtual size_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0; 170 171 virtual int newAudioSessionId() = 0; 172 173 virtual void acquireAudioSessionId(int audioSession) = 0; 174 virtual void releaseAudioSessionId(int audioSession) = 0; 175 176 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0; 177 178 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0; 179 180 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID, 181 effect_descriptor_t *pDescriptor) const = 0; 182 183 virtual sp<IEffect> createEffect( 184 effect_descriptor_t *pDesc, 185 const sp<IEffectClient>& client, 186 int32_t priority, 187 audio_io_handle_t output, 188 int sessionId, 189 status_t *status, 190 int *id, 191 int *enabled) = 0; 192 193 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput, 194 audio_io_handle_t dstOutput) = 0; 195 196 virtual audio_module_handle_t loadHwModule(const char *name) = 0; 197 198 // helpers for android.media.AudioManager.getProperty(), see description there for meaning 199 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation 200 // that looks on primary device for a stream with fast flag, primary flag, or first one. 201 virtual uint32_t getPrimaryOutputSamplingRate() = 0; 202 virtual size_t getPrimaryOutputFrameCount() = 0; 203 204 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute, 205 // and should be called at most once. For a definition of what "low RAM" means, see 206 // android.app.ActivityManager.isLowRamDevice(). 207 virtual status_t setLowRamDevice(bool isLowRamDevice) = 0; 208}; 209 210 211// ---------------------------------------------------------------------------- 212 213class BnAudioFlinger : public BnInterface<IAudioFlinger> 214{ 215public: 216 virtual status_t onTransact( uint32_t code, 217 const Parcel& data, 218 Parcel* reply, 219 uint32_t flags = 0); 220}; 221 222// ---------------------------------------------------------------------------- 223 224}; // namespace android 225 226#endif // ANDROID_IAUDIOFLINGER_H 227