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