• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.AudioPatchFw;
20 import android.media.AudioPolicyConfig;
21 import android.media.AudioPortFw;
22 import android.media.AudioPortConfigFw;
23 import android.media.AudioUniqueIdUse;
24 import android.media.AudioVibratorInfo;
25 import android.media.CreateEffectRequest;
26 import android.media.CreateEffectResponse;
27 import android.media.CreateRecordRequest;
28 import android.media.CreateRecordResponse;
29 import android.media.CreateTrackRequest;
30 import android.media.CreateTrackResponse;
31 import android.media.DeviceConnectedState;
32 import android.media.OpenInputRequest;
33 import android.media.OpenInputResponse;
34 import android.media.OpenOutputRequest;
35 import android.media.OpenOutputResponse;
36 import android.media.EffectDescriptor;
37 import android.media.IAudioFlingerClient;
38 import android.media.IAudioRecord;
39 import android.media.IAudioTrack;
40 import android.media.ISoundDose;
41 import android.media.ISoundDoseCallback;
42 import android.media.MicrophoneInfoFw;
43 import android.media.RenderPosition;
44 import android.media.TrackInternalMuteInfo;
45 import android.media.TrackSecondaryOutputInfo;
46 import android.media.audio.common.AudioChannelLayout;
47 import android.media.audio.common.AudioFormatDescription;
48 import android.media.audio.common.AudioLatencyMode;
49 import android.media.audio.common.AudioMMapPolicyInfo;
50 import android.media.audio.common.AudioMMapPolicyType;
51 import android.media.audio.common.AudioMode;
52 import android.media.audio.common.AudioStreamType;
53 import android.media.audio.common.AudioUuid;
54 
55 /**
56  * {@hide}
57  */
58 interface IAudioFlingerService {
59     /**
60      * Creates an audio track and registers it with AudioFlinger, or null if the track cannot be
61      * created.
62      */
createTrack(in CreateTrackRequest request)63     CreateTrackResponse createTrack(in CreateTrackRequest request);
64 
createRecord(in CreateRecordRequest request)65     CreateRecordResponse createRecord(in CreateRecordRequest request);
66 
67     // FIXME Surprisingly, format/latency don't work for input handles
68 
69     /**
70      * Queries the audio hardware state. This state never changes, and therefore can be cached.
71      */
sampleRate(int ioHandle)72     int sampleRate(int /* audio_io_handle_t */ ioHandle);
73 
format(int output)74     AudioFormatDescription format(int /* audio_io_handle_t */ output);
75 
frameCount(int ioHandle)76     long frameCount(int /* audio_io_handle_t */ ioHandle);
77 
78     /**
79      * Return the estimated latency in milliseconds.
80      */
latency(int output)81     int latency(int  /* audio_io_handle_t */ output);
82 
83     /*
84      * Sets/gets the audio hardware state. This will probably be used by
85      * the preference panel, mostly.
86      */
setMasterVolume(float value)87     void setMasterVolume(float value);
setMasterMute(boolean muted)88     void setMasterMute(boolean muted);
89 
masterVolume()90     float masterVolume();
masterMute()91     boolean masterMute();
92 
setMasterBalance(float balance)93     void setMasterBalance(float balance);
getMasterBalance()94     float getMasterBalance();
95 
96     /*
97      * Set/gets stream type state. This will probably be used by
98      * the preference panel, mostly.
99      */
setStreamVolume(AudioStreamType stream, float value, int output)100     void setStreamVolume(AudioStreamType stream, float value, int /* audio_io_handle_t */ output);
setStreamMute(AudioStreamType stream, boolean muted)101     void setStreamMute(AudioStreamType stream, boolean muted);
streamVolume(AudioStreamType stream, int output)102     float streamVolume(AudioStreamType stream, int /* audio_io_handle_t */ output);
streamMute(AudioStreamType stream)103     boolean streamMute(AudioStreamType stream);
104 
105     // set audio mode.
setMode(AudioMode mode)106     void setMode(AudioMode mode);
107 
108     // mic mute/state
setMicMute(boolean state)109     void setMicMute(boolean state);
getMicMute()110     boolean getMicMute();
setRecordSilenced(int portId, boolean silenced)111     void setRecordSilenced(int /* audio_port_handle_t */ portId,
112                            boolean silenced);
113 
setParameters(int ioHandle, @utf8InCpp String keyValuePairs)114     void setParameters(int /* audio_io_handle_t */ ioHandle,
115                        @utf8InCpp String keyValuePairs);
getParameters(int ioHandle, @utf8InCpp String keys)116     @utf8InCpp String getParameters(int /* audio_io_handle_t */ ioHandle,
117                                     @utf8InCpp String keys);
118 
119     // Register an object to receive audio input/output change and track notifications.
120     // For a given calling pid, AudioFlinger disregards any registrations after the first.
121     // Thus the IAudioFlingerClient must be a singleton per process.
registerClient(IAudioFlingerClient client)122     void registerClient(IAudioFlingerClient client);
123 
124     // Retrieve the audio recording buffer size in bytes.
125     // FIXME This API assumes a route, and so should be deprecated.
getInputBufferSize(int sampleRate, in AudioFormatDescription format, in AudioChannelLayout channelMask)126     long getInputBufferSize(int sampleRate,
127                             in AudioFormatDescription format,
128                             in AudioChannelLayout channelMask);
129 
openOutput(in OpenOutputRequest request)130     OpenOutputResponse openOutput(in OpenOutputRequest request);
openDuplicateOutput(int output1, int output2)131     int /* audio_io_handle_t */ openDuplicateOutput(int /* audio_io_handle_t */ output1,
132                                                     int /* audio_io_handle_t */ output2);
closeOutput(int output)133     void closeOutput(int /* audio_io_handle_t */ output);
suspendOutput(int output)134     void suspendOutput(int /* audio_io_handle_t */ output);
restoreOutput(int output)135     void restoreOutput(int /* audio_io_handle_t */ output);
136 
openInput(in OpenInputRequest request)137     OpenInputResponse openInput(in OpenInputRequest request);
closeInput(int input)138     void closeInput(int /* audio_io_handle_t */ input);
139 
setVoiceVolume(float volume)140     void setVoiceVolume(float volume);
141 
getRenderPosition(int output)142     RenderPosition getRenderPosition(int /* audio_io_handle_t */ output);
143 
getInputFramesLost(int ioHandle)144     int getInputFramesLost(int /* audio_io_handle_t */ ioHandle);
145 
newAudioUniqueId(AudioUniqueIdUse use)146     int /* audio_unique_id_t */ newAudioUniqueId(AudioUniqueIdUse use);
147 
acquireAudioSessionId(int audioSession, int pid, int uid)148     void acquireAudioSessionId(int /* audio_session_t */ audioSession,
149                                int /* pid_t */ pid,
150                                int /* uid_t */ uid);
releaseAudioSessionId(int audioSession, int pid)151     void releaseAudioSessionId(int /* audio_session_t */ audioSession,
152                                int /* pid_t */ pid);
153 
queryNumberEffects()154     int queryNumberEffects();
155 
queryEffect(int index)156     EffectDescriptor queryEffect(int index);
157 
158     /** preferredTypeFlag is interpreted as a uint32_t with the "effect flag" format. */
getEffectDescriptor(in AudioUuid effectUUID, in AudioUuid typeUUID, int preferredTypeFlag)159     EffectDescriptor getEffectDescriptor(in AudioUuid effectUUID,
160                                          in AudioUuid typeUUID,
161                                          int preferredTypeFlag);
162 
createEffect(in CreateEffectRequest request)163     CreateEffectResponse createEffect(in CreateEffectRequest request);
164 
moveEffects(int session, int srcOutput, int dstOutput)165     void moveEffects(int /* audio_session_t */ session,
166                      int /* audio_io_handle_t */ srcOutput,
167                      int /* audio_io_handle_t */ dstOutput);
168 
setEffectSuspended(int effectId, int sessionId, boolean suspended)169     void setEffectSuspended(int effectId,
170                             int /* audio_session_t */ sessionId,
171                             boolean suspended);
172 
loadHwModule(@tf8InCpp String name)173     int /* audio_module_handle_t */ loadHwModule(@utf8InCpp String name);
174 
175     // helpers for android.media.AudioManager.getProperty(), see description there for meaning
176     // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
177     // that looks on primary device for a stream with fast flag, primary flag, or first one.
getPrimaryOutputSamplingRate()178     int getPrimaryOutputSamplingRate();
getPrimaryOutputFrameCount()179     long getPrimaryOutputFrameCount();
180 
181     // Intended for AudioService to inform AudioFlinger of device's low RAM attribute,
182     // and should be called at most once.  For a definition of what "low RAM" means, see
183     // android.app.ActivityManager.isLowRamDevice().  The totalMemory parameter
184     // is obtained from android.app.ActivityManager.MemoryInfo.totalMem.
setLowRamDevice(boolean isLowRamDevice, long totalMemory)185     void setLowRamDevice(boolean isLowRamDevice, long totalMemory);
186 
187     /* Get attributes for a given audio port */
getAudioPort(in AudioPortFw port)188     AudioPortFw getAudioPort(in AudioPortFw port);
189 
190     /* Create an audio patch between several source and sink ports */
createAudioPatch(in AudioPatchFw patch)191     int /* audio_patch_handle_t */ createAudioPatch(in AudioPatchFw patch);
192 
193     /* Release an audio patch */
releaseAudioPatch(int handle)194     void releaseAudioPatch(int /* audio_patch_handle_t */ handle);
195 
196     /* List existing audio patches */
listAudioPatches(int maxCount)197     AudioPatchFw[] listAudioPatches(int maxCount);
198     /* Set audio port configuration */
setAudioPortConfig(in AudioPortConfigFw config)199     void setAudioPortConfig(in AudioPortConfigFw config);
200 
201     /* Get the HW synchronization source used for an audio session */
getAudioHwSyncForSession(int sessionId)202     int /* audio_hw_sync_t */ getAudioHwSyncForSession(int /* audio_session_t */ sessionId);
203 
204     /* Indicate JAVA services are ready (scheduling, power management ...) */
systemReady()205     oneway void systemReady();
206 
207     /* Indicate audio policy service is ready */
audioPolicyReady()208     oneway void audioPolicyReady();
209 
210     // Returns the number of frames per audio HAL buffer.
frameCountHAL(int ioHandle)211     long frameCountHAL(int /* audio_io_handle_t */ ioHandle);
212 
213     /* List available microphones and their characteristics */
getMicrophones()214     MicrophoneInfoFw[] getMicrophones();
215 
setAudioHalPids(in int[] pids)216     void setAudioHalPids(in int[] /* pid_t[] */ pids);
217 
218     // Set vibrators' information.
219     // The value will be used to initialize HapticGenerator.
setVibratorInfos(in AudioVibratorInfo[] vibratorInfos)220     void setVibratorInfos(in AudioVibratorInfo[] vibratorInfos);
221 
222     // Update secondary outputs.
223     // This usually happens when there is a dynamic policy registered.
updateSecondaryOutputs( in TrackSecondaryOutputInfo[] trackSecondaryOutputInfos)224     void updateSecondaryOutputs(
225             in TrackSecondaryOutputInfo[] trackSecondaryOutputInfos);
226 
getMmapPolicyInfos(AudioMMapPolicyType policyType)227     AudioMMapPolicyInfo[] getMmapPolicyInfos(AudioMMapPolicyType policyType);
228 
getAAudioMixerBurstCount()229     int getAAudioMixerBurstCount();
230 
getAAudioHardwareBurstMinUsec()231     int getAAudioHardwareBurstMinUsec();
232 
setDeviceConnectedState(in AudioPortFw devicePort, DeviceConnectedState state)233     void setDeviceConnectedState(in AudioPortFw devicePort, DeviceConnectedState state);
234 
235     // Used for tests only. Requires AIDL HAL to work.
setSimulateDeviceConnections(boolean enabled)236     void setSimulateDeviceConnections(boolean enabled);
237 
238     /**
239      * Requests a given latency mode (See AudioLatencyMode.aidl) on an output stream.
240      * This can be used when some use case on a given mixer/stream can only be enabled
241      * if a specific latency mode is selected on the audio path below the HAL.
242      * For instance spatial audio with head tracking.
243      * output is the I/O handle of the output stream for which the request is made.
244      * latencyMode is the requested latency mode.
245      */
setRequestedLatencyMode(int output, AudioLatencyMode latencyMode)246      void setRequestedLatencyMode(int output, AudioLatencyMode latencyMode);
247 
248     /**
249      * Queries the list of latency modes (See LatencyMode.aidl) supported by an output stream.
250      * output is the I/O handle of the output stream to which the query applies.
251      * returns the list of supported latency modes.
252      */
getSupportedLatencyModes(int output)253     AudioLatencyMode[] getSupportedLatencyModes(int output);
254 
255     /**
256      * Requests if the implementation supports controlling the latency modes
257      * over the Bluetooth A2DP or LE Audio links. If it does,
258      * setRequestedLatencyMode() and getSupportedLatencyModes() APIs can also be used
259      * for streams routed to Bluetooth and not just for the spatializer output.
260      */
supportsBluetoothVariableLatency()261      boolean supportsBluetoothVariableLatency();
262 
263     /**
264      * Enables or disables the variable Bluetooth latency control mechanism in the
265      * audio framework and the audio HAL. This does not apply to the latency mode control
266      * on the spatializer output as this is a built-in feature.
267      */
setBluetoothVariableLatencyEnabled(boolean enabled)268     void setBluetoothVariableLatencyEnabled(boolean enabled);
269 
270     /**
271      * Indicates if the variable Bluetooth latency control mechanism is enabled or disabled.
272      */
isBluetoothVariableLatencyEnabled()273     boolean isBluetoothVariableLatencyEnabled();
274 
275     /**
276      * Registers the sound dose callback and returns the interface for executing
277      * sound dose methods on the audio server.
278      */
getSoundDoseInterface(in ISoundDoseCallback callback)279     ISoundDose getSoundDoseInterface(in ISoundDoseCallback callback);
280 
281     /**
282      * Invalidate all tracks with given port ids.
283      */
invalidateTracks(in int[] portIds)284     void invalidateTracks(in int[] /* audio_port_handle_t[] */ portIds);
285 
286     /**
287      * Only implemented for AIDL. Provides the APM configuration which
288      * used to be in the XML file.
289      */
getAudioPolicyConfig()290     AudioPolicyConfig getAudioPolicyConfig();
291 
292     /**
293      * Get the attributes of the mix port when connecting to the given device port.
294      */
getAudioMixPort(in AudioPortFw devicePort, in AudioPortFw mixPort)295     AudioPortFw getAudioMixPort(in AudioPortFw devicePort, in AudioPortFw mixPort);
296 
297     /**
298      * Set internal mute for a list of tracks.
299      */
setTracksInternalMute(in TrackInternalMuteInfo[] tracksInternalMute)300     void setTracksInternalMute(in TrackInternalMuteInfo[] tracksInternalMute);
301 
302     /*
303      * Reset Circular references in AudioFlinger service.
304      * Test API
305      */
resetReferencesForTest()306      void resetReferencesForTest();
307 
308     // When adding a new method, please review and update
309     // IAudioFlinger.h AudioFlingerServerAdapter::Delegate::TransactionCode
310     // AudioFlinger.cpp AudioFlinger::onTransactWrapper()
311     // AudioFlinger.cpp IAUDIOFLINGER_BINDER_METHOD_MACRO_LIST
312 }
313