1 /* 2 * Copyright (C) 2020 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 package android.media; 18 19 import android.media.AudioMode; 20 import android.media.AudioPatch; 21 import android.media.AudioPort; 22 import android.media.AudioPortConfig; 23 import android.media.AudioStreamType; 24 import android.media.AudioUniqueIdUse; 25 import android.media.AudioUuid; 26 import android.media.AudioVibratorInfo; 27 import android.media.CreateEffectRequest; 28 import android.media.CreateEffectResponse; 29 import android.media.CreateRecordRequest; 30 import android.media.CreateRecordResponse; 31 import android.media.CreateTrackRequest; 32 import android.media.CreateTrackResponse; 33 import android.media.OpenInputRequest; 34 import android.media.OpenInputResponse; 35 import android.media.OpenOutputRequest; 36 import android.media.OpenOutputResponse; 37 import android.media.EffectDescriptor; 38 import android.media.IAudioFlingerClient; 39 import android.media.IAudioRecord; 40 import android.media.IAudioTrack; 41 import android.media.MicrophoneInfoData; 42 import android.media.RenderPosition; 43 import android.media.TrackSecondaryOutputInfo; 44 import android.media.audio.common.AudioFormat; 45 46 /** 47 * {@hide} 48 */ 49 interface IAudioFlingerService { 50 /** 51 * Creates an audio track and registers it with AudioFlinger, or null if the track cannot be 52 * created. 53 */ createTrack(in CreateTrackRequest request)54 CreateTrackResponse createTrack(in CreateTrackRequest request); 55 createRecord(in CreateRecordRequest request)56 CreateRecordResponse createRecord(in CreateRecordRequest request); 57 58 // FIXME Surprisingly, format/latency don't work for input handles 59 60 /** 61 * Queries the audio hardware state. This state never changes, and therefore can be cached. 62 */ sampleRate(int ioHandle)63 int sampleRate(int /* audio_io_handle_t */ ioHandle); 64 format(int output)65 AudioFormat format(int /* audio_io_handle_t */ output); 66 frameCount(int ioHandle)67 long frameCount(int /* audio_io_handle_t */ ioHandle); 68 69 /** 70 * Return the estimated latency in milliseconds. 71 */ latency(int output)72 int latency(int /* audio_io_handle_t */ output); 73 74 /* 75 * Sets/gets the audio hardware state. This will probably be used by 76 * the preference panel, mostly. 77 */ setMasterVolume(float value)78 void setMasterVolume(float value); setMasterMute(boolean muted)79 void setMasterMute(boolean muted); 80 masterVolume()81 float masterVolume(); masterMute()82 boolean masterMute(); 83 setMasterBalance(float balance)84 void setMasterBalance(float balance); getMasterBalance()85 float getMasterBalance(); 86 87 /* 88 * Set/gets stream type state. This will probably be used by 89 * the preference panel, mostly. 90 */ setStreamVolume(AudioStreamType stream, float value, int output)91 void setStreamVolume(AudioStreamType stream, float value, int /* audio_io_handle_t */ output); setStreamMute(AudioStreamType stream, boolean muted)92 void setStreamMute(AudioStreamType stream, boolean muted); streamVolume(AudioStreamType stream, int output)93 float streamVolume(AudioStreamType stream, int /* audio_io_handle_t */ output); streamMute(AudioStreamType stream)94 boolean streamMute(AudioStreamType stream); 95 96 // set audio mode. setMode(AudioMode mode)97 void setMode(AudioMode mode); 98 99 // mic mute/state setMicMute(boolean state)100 void setMicMute(boolean state); getMicMute()101 boolean getMicMute(); setRecordSilenced(int portId, boolean silenced)102 void setRecordSilenced(int /* audio_port_handle_t */ portId, 103 boolean silenced); 104 setParameters(int ioHandle, @utf8InCpp String keyValuePairs)105 void setParameters(int /* audio_io_handle_t */ ioHandle, 106 @utf8InCpp String keyValuePairs); getParameters(int ioHandle, @utf8InCpp String keys)107 @utf8InCpp String getParameters(int /* audio_io_handle_t */ ioHandle, 108 @utf8InCpp String keys); 109 110 // Register an object to receive audio input/output change and track notifications. 111 // For a given calling pid, AudioFlinger disregards any registrations after the first. 112 // Thus the IAudioFlingerClient must be a singleton per process. registerClient(IAudioFlingerClient client)113 void registerClient(IAudioFlingerClient client); 114 115 // Retrieve the audio recording buffer size in bytes. 116 // FIXME This API assumes a route, and so should be deprecated. getInputBufferSize(int sampleRate, AudioFormat format, int channelMask)117 long getInputBufferSize(int sampleRate, 118 AudioFormat format, 119 int /* audio_channel_mask_t */ channelMask); 120 openOutput(in OpenOutputRequest request)121 OpenOutputResponse openOutput(in OpenOutputRequest request); openDuplicateOutput(int output1, int output2)122 int /* audio_io_handle_t */ openDuplicateOutput(int /* audio_io_handle_t */ output1, 123 int /* audio_io_handle_t */ output2); closeOutput(int output)124 void closeOutput(int /* audio_io_handle_t */ output); suspendOutput(int output)125 void suspendOutput(int /* audio_io_handle_t */ output); restoreOutput(int output)126 void restoreOutput(int /* audio_io_handle_t */ output); 127 openInput(in OpenInputRequest request)128 OpenInputResponse openInput(in OpenInputRequest request); closeInput(int input)129 void closeInput(int /* audio_io_handle_t */ input); 130 invalidateStream(AudioStreamType stream)131 void invalidateStream(AudioStreamType stream); 132 setVoiceVolume(float volume)133 void setVoiceVolume(float volume); 134 getRenderPosition(int output)135 RenderPosition getRenderPosition(int /* audio_io_handle_t */ output); 136 getInputFramesLost(int ioHandle)137 int getInputFramesLost(int /* audio_io_handle_t */ ioHandle); 138 newAudioUniqueId(AudioUniqueIdUse use)139 int /* audio_unique_id_t */ newAudioUniqueId(AudioUniqueIdUse use); 140 acquireAudioSessionId(int audioSession, int pid, int uid)141 void acquireAudioSessionId(int /* audio_session_t */ audioSession, 142 int /* pid_t */ pid, 143 int /* uid_t */ uid); releaseAudioSessionId(int audioSession, int pid)144 void releaseAudioSessionId(int /* audio_session_t */ audioSession, 145 int /* pid_t */ pid); 146 queryNumberEffects()147 int queryNumberEffects(); 148 queryEffect(int index)149 EffectDescriptor queryEffect(int index); 150 151 /** preferredTypeFlag is interpreted as a uint32_t with the "effect flag" format. */ getEffectDescriptor(in AudioUuid effectUUID, in AudioUuid typeUUID, int preferredTypeFlag)152 EffectDescriptor getEffectDescriptor(in AudioUuid effectUUID, 153 in AudioUuid typeUUID, 154 int preferredTypeFlag); 155 createEffect(in CreateEffectRequest request)156 CreateEffectResponse createEffect(in CreateEffectRequest request); 157 moveEffects(int session, int srcOutput, int dstOutput)158 void moveEffects(int /* audio_session_t */ session, 159 int /* audio_io_handle_t */ srcOutput, 160 int /* audio_io_handle_t */ dstOutput); 161 setEffectSuspended(int effectId, int sessionId, boolean suspended)162 void setEffectSuspended(int effectId, 163 int /* audio_session_t */ sessionId, 164 boolean suspended); 165 loadHwModule(@tf8InCpp String name)166 int /* audio_module_handle_t */ loadHwModule(@utf8InCpp String name); 167 168 // helpers for android.media.AudioManager.getProperty(), see description there for meaning 169 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation 170 // that looks on primary device for a stream with fast flag, primary flag, or first one. getPrimaryOutputSamplingRate()171 int getPrimaryOutputSamplingRate(); getPrimaryOutputFrameCount()172 long getPrimaryOutputFrameCount(); 173 174 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute, 175 // and should be called at most once. For a definition of what "low RAM" means, see 176 // android.app.ActivityManager.isLowRamDevice(). The totalMemory parameter 177 // is obtained from android.app.ActivityManager.MemoryInfo.totalMem. setLowRamDevice(boolean isLowRamDevice, long totalMemory)178 void setLowRamDevice(boolean isLowRamDevice, long totalMemory); 179 180 /* Get attributes for a given audio port */ getAudioPort(in AudioPort port)181 AudioPort getAudioPort(in AudioPort port); 182 183 /* Create an audio patch between several source and sink ports */ createAudioPatch(in AudioPatch patch)184 int /* audio_patch_handle_t */ createAudioPatch(in AudioPatch patch); 185 186 /* Release an audio patch */ releaseAudioPatch(int handle)187 void releaseAudioPatch(int /* audio_patch_handle_t */ handle); 188 189 /* List existing audio patches */ listAudioPatches(int maxCount)190 AudioPatch[] listAudioPatches(int maxCount); 191 /* Set audio port configuration */ setAudioPortConfig(in AudioPortConfig config)192 void setAudioPortConfig(in AudioPortConfig config); 193 194 /* Get the HW synchronization source used for an audio session */ getAudioHwSyncForSession(int sessionId)195 int /* audio_hw_sync_t */ getAudioHwSyncForSession(int /* audio_session_t */ sessionId); 196 197 /* Indicate JAVA services are ready (scheduling, power management ...) */ systemReady()198 oneway void systemReady(); 199 200 // Returns the number of frames per audio HAL buffer. frameCountHAL(int ioHandle)201 long frameCountHAL(int /* audio_io_handle_t */ ioHandle); 202 203 /* List available microphones and their characteristics */ getMicrophones()204 MicrophoneInfoData[] getMicrophones(); 205 setAudioHalPids(in int[] pids)206 void setAudioHalPids(in int[] /* pid_t[] */ pids); 207 208 // Set vibrators' information. 209 // The value will be used to initialize HapticGenerator. setVibratorInfos(in AudioVibratorInfo[] vibratorInfos)210 void setVibratorInfos(in AudioVibratorInfo[] vibratorInfos); 211 212 // Update secondary outputs. 213 // This usually happens when there is a dynamic policy registered. updateSecondaryOutputs( in TrackSecondaryOutputInfo[] trackSecondaryOutputInfos)214 void updateSecondaryOutputs( 215 in TrackSecondaryOutputInfo[] trackSecondaryOutputInfos); 216 } 217