• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/AidlConversion.h>
28 #include <media/AudioClient.h>
29 #include <media/AudioCommonTypes.h>
30 #include <media/DeviceDescriptorBase.h>
31 #include <system/audio.h>
32 #include <system/audio_effect.h>
33 #include <system/audio_policy.h>
34 #include <utils/String8.h>
35 #include <media/MicrophoneInfo.h>
36 #include <map>
37 #include <string>
38 #include <vector>
39 
40 #include <android/media/AudioVibratorInfo.h>
41 #include <android/media/BnAudioFlingerService.h>
42 #include <android/media/BpAudioFlingerService.h>
43 #include <android/content/AttributionSourceState.h>
44 #include "android/media/CreateEffectRequest.h"
45 #include "android/media/CreateEffectResponse.h"
46 #include "android/media/CreateRecordRequest.h"
47 #include "android/media/CreateRecordResponse.h"
48 #include "android/media/CreateTrackRequest.h"
49 #include "android/media/CreateTrackResponse.h"
50 #include "android/media/IAudioRecord.h"
51 #include "android/media/IAudioFlingerClient.h"
52 #include "android/media/IAudioTrack.h"
53 #include "android/media/IAudioTrackCallback.h"
54 #include "android/media/IEffect.h"
55 #include "android/media/IEffectClient.h"
56 #include "android/media/OpenInputRequest.h"
57 #include "android/media/OpenInputResponse.h"
58 #include "android/media/OpenOutputRequest.h"
59 #include "android/media/OpenOutputResponse.h"
60 #include "android/media/TrackSecondaryOutputInfo.h"
61 
62 namespace android {
63 
64 // ----------------------------------------------------------------------------
65 
66 class IAudioFlinger : public RefBase {
67 public:
68     static constexpr char DEFAULT_SERVICE_NAME[] = "media.audio_flinger";
69 
70     virtual ~IAudioFlinger() = default;
71 
72     /* CreateTrackInput contains all input arguments sent by AudioTrack to AudioFlinger
73      * when calling createTrack() including arguments that will be updated by AudioFlinger
74      * and returned in CreateTrackOutput object
75      */
76     class CreateTrackInput {
77     public:
78         /* input */
79         audio_attributes_t attr;
80         audio_config_t config;
81         AudioClient clientInfo;
82         sp<IMemory> sharedBuffer;
83         uint32_t notificationsPerBuffer;
84         float speed;
85         sp<media::IAudioTrackCallback> audioTrackCallback;
86 
87         /* input/output */
88         audio_output_flags_t flags;
89         size_t frameCount;
90         size_t notificationFrameCount;
91         audio_port_handle_t selectedDeviceId;
92         audio_session_t sessionId;
93 
94         ConversionResult<media::CreateTrackRequest> toAidl() const;
95         static ConversionResult<CreateTrackInput> fromAidl(const media::CreateTrackRequest& aidl);
96     };
97 
98     /* CreateTrackOutput contains all output arguments returned by AudioFlinger to AudioTrack
99      * when calling createTrack() including arguments that were passed as I/O for update by
100      * CreateTrackInput.
101      */
102     class CreateTrackOutput {
103     public:
104         /* input/output */
105         audio_output_flags_t flags;
106         size_t frameCount;
107         size_t notificationFrameCount;
108         audio_port_handle_t selectedDeviceId;
109         audio_session_t sessionId;
110 
111         /* output */
112         uint32_t sampleRate;
113         audio_stream_type_t streamType;
114         size_t   afFrameCount;
115         uint32_t afSampleRate;
116         uint32_t afLatencyMs;
117         audio_io_handle_t outputId;
118         audio_port_handle_t portId;
119         sp<media::IAudioTrack> audioTrack;
120 
121         ConversionResult<media::CreateTrackResponse> toAidl() const;
122         static ConversionResult<CreateTrackOutput> fromAidl(const media::CreateTrackResponse& aidl);
123     };
124 
125     /* CreateRecordInput contains all input arguments sent by AudioRecord to AudioFlinger
126      * when calling createRecord() including arguments that will be updated by AudioFlinger
127      * and returned in CreateRecordOutput object
128      */
129     class CreateRecordInput {
130     public:
131         /* input */
132         audio_attributes_t attr;
133         audio_config_base_t config;
134         AudioClient clientInfo;
135         audio_unique_id_t riid;
136         int32_t maxSharedAudioHistoryMs;
137 
138         /* input/output */
139         audio_input_flags_t flags;
140         size_t frameCount;
141         size_t notificationFrameCount;
142         audio_port_handle_t selectedDeviceId;
143         audio_session_t sessionId;
144 
145         ConversionResult<media::CreateRecordRequest> toAidl() const;
146         static ConversionResult<CreateRecordInput> fromAidl(const media::CreateRecordRequest& aidl);
147     };
148 
149     /* CreateRecordOutput contains all output arguments returned by AudioFlinger to AudioRecord
150      * when calling createRecord() including arguments that were passed as I/O for update by
151      * CreateRecordInput.
152      */
153     class CreateRecordOutput {
154     public:
155         /* input/output */
156         audio_input_flags_t flags;
157         size_t frameCount;
158         size_t notificationFrameCount;
159         audio_port_handle_t selectedDeviceId;
160         audio_session_t sessionId;
161 
162         /* output */
163         uint32_t sampleRate;
164         audio_io_handle_t inputId;
165         sp<IMemory> cblk;
166         sp<IMemory> buffers;
167         audio_port_handle_t portId;
168         sp<media::IAudioRecord> audioRecord;
169 
170         ConversionResult<media::CreateRecordResponse> toAidl() const;
171         static ConversionResult<CreateRecordOutput>
172         fromAidl(const media::CreateRecordResponse& aidl);
173     };
174 
175     /* create an audio track and registers it with AudioFlinger.
176      * The audioTrack field will be null if the track cannot be created and the status will reflect
177      * failure.
178      */
179     virtual status_t createTrack(const media::CreateTrackRequest& input,
180                                  media::CreateTrackResponse& output) = 0;
181 
182     /* create an audio record and registers it with AudioFlinger.
183      * The audioRecord field will be null if the track cannot be created and the status will reflect
184      * failure.
185      */
186     virtual status_t createRecord(const media::CreateRecordRequest& input,
187                                   media::CreateRecordResponse& output) = 0;
188 
189     // FIXME Surprisingly, format/latency don't work for input handles
190 
191     /* query the audio hardware state. This state never changes,
192      * and therefore can be cached.
193      */
194     virtual     uint32_t    sampleRate(audio_io_handle_t ioHandle) const = 0;
195 
196     // reserved; formerly channelCount()
197 
198     virtual     audio_format_t format(audio_io_handle_t output) const = 0;
199     virtual     size_t      frameCount(audio_io_handle_t ioHandle) const = 0;
200 
201     // return estimated latency in milliseconds
202     virtual     uint32_t    latency(audio_io_handle_t output) const = 0;
203 
204     /* set/get the audio hardware state. This will probably be used by
205      * the preference panel, mostly.
206      */
207     virtual     status_t    setMasterVolume(float value) = 0;
208     virtual     status_t    setMasterMute(bool muted) = 0;
209 
210     virtual     float       masterVolume() const = 0;
211     virtual     bool        masterMute() const = 0;
212 
213     virtual     status_t    setMasterBalance(float balance) = 0;
214     virtual     status_t    getMasterBalance(float *balance) const = 0;
215 
216     /* set/get stream type state. This will probably be used by
217      * the preference panel, mostly.
218      */
219     virtual     status_t    setStreamVolume(audio_stream_type_t stream, float value,
220                                     audio_io_handle_t output) = 0;
221     virtual     status_t    setStreamMute(audio_stream_type_t stream, bool muted) = 0;
222 
223     virtual     float       streamVolume(audio_stream_type_t stream,
224                                     audio_io_handle_t output) const = 0;
225     virtual     bool        streamMute(audio_stream_type_t stream) const = 0;
226 
227     // set audio mode
228     virtual     status_t    setMode(audio_mode_t mode) = 0;
229 
230     // mic mute/state
231     virtual     status_t    setMicMute(bool state) = 0;
232     virtual     bool        getMicMute() const = 0;
233     virtual     void        setRecordSilenced(audio_port_handle_t portId, bool silenced) = 0;
234 
235     virtual     status_t    setParameters(audio_io_handle_t ioHandle,
236                                     const String8& keyValuePairs) = 0;
237     virtual     String8     getParameters(audio_io_handle_t ioHandle, const String8& keys)
238                                     const = 0;
239 
240     // Register an object to receive audio input/output change and track notifications.
241     // For a given calling pid, AudioFlinger disregards any registrations after the first.
242     // Thus the IAudioFlingerClient must be a singleton per process.
243     virtual void registerClient(const sp<media::IAudioFlingerClient>& client) = 0;
244 
245     // retrieve the audio recording buffer size in bytes
246     // FIXME This API assumes a route, and so should be deprecated.
247     virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
248             audio_channel_mask_t channelMask) const = 0;
249 
250     virtual status_t openOutput(const media::OpenOutputRequest& request,
251                                 media::OpenOutputResponse* response) = 0;
252     virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
253                                     audio_io_handle_t output2) = 0;
254     virtual status_t closeOutput(audio_io_handle_t output) = 0;
255     virtual status_t suspendOutput(audio_io_handle_t output) = 0;
256     virtual status_t restoreOutput(audio_io_handle_t output) = 0;
257 
258     virtual status_t openInput(const media::OpenInputRequest& request,
259                                media::OpenInputResponse* response) = 0;
260 
261     virtual status_t closeInput(audio_io_handle_t input) = 0;
262 
263     virtual status_t invalidateStream(audio_stream_type_t stream) = 0;
264 
265     virtual status_t setVoiceVolume(float volume) = 0;
266 
267     virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
268                                     audio_io_handle_t output) const = 0;
269 
270     virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
271 
272     virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use) = 0;
273 
274     virtual void acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) = 0;
275     virtual void releaseAudioSessionId(audio_session_t audioSession, pid_t pid) = 0;
276 
277     virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
278 
279     virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
280 
281     virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
282                                          const effect_uuid_t *pTypeUUID,
283                                          uint32_t preferredTypeFlag,
284                                          effect_descriptor_t *pDescriptor) const = 0;
285 
286     virtual status_t createEffect(const media::CreateEffectRequest& request,
287                                   media::CreateEffectResponse* response) = 0;
288 
289     virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
290                                     audio_io_handle_t dstOutput) = 0;
291 
292     virtual void setEffectSuspended(int effectId,
293                                     audio_session_t sessionId,
294                                     bool suspended) = 0;
295 
296     virtual audio_module_handle_t loadHwModule(const char *name) = 0;
297 
298     // helpers for android.media.AudioManager.getProperty(), see description there for meaning
299     // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
300     // that looks on primary device for a stream with fast flag, primary flag, or first one.
301     virtual uint32_t getPrimaryOutputSamplingRate() = 0;
302     virtual size_t getPrimaryOutputFrameCount() = 0;
303 
304     // Intended for AudioService to inform AudioFlinger of device's low RAM attribute,
305     // and should be called at most once.  For a definition of what "low RAM" means, see
306     // android.app.ActivityManager.isLowRamDevice().  The totalMemory parameter
307     // is obtained from android.app.ActivityManager.MemoryInfo.totalMem.
308     virtual status_t setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) = 0;
309 
310     /* Get attributes for a given audio port */
311     virtual status_t getAudioPort(struct audio_port_v7 *port) = 0;
312 
313     /* Create an audio patch between several source and sink ports */
314     virtual status_t createAudioPatch(const struct audio_patch *patch,
315                                        audio_patch_handle_t *handle) = 0;
316 
317     /* Release an audio patch */
318     virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0;
319 
320     /* List existing audio patches */
321     virtual status_t listAudioPatches(unsigned int *num_patches,
322                                       struct audio_patch *patches) = 0;
323     /* Set audio port configuration */
324     virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
325 
326     /* Get the HW synchronization source used for an audio session */
327     virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId) = 0;
328 
329     /* Indicate JAVA services are ready (scheduling, power management ...) */
330     virtual status_t systemReady() = 0;
331 
332     // Returns the number of frames per audio HAL buffer.
333     virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const = 0;
334 
335     /* List available microphones and their characteristics */
336     virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones) = 0;
337 
338     virtual status_t setAudioHalPids(const std::vector<pid_t>& pids) = 0;
339 
340     // Set vibrators' information.
341     // The values will be used to initialize HapticGenerator.
342     virtual status_t setVibratorInfos(
343             const std::vector<media::AudioVibratorInfo>& vibratorInfos) = 0;
344 
345     virtual status_t updateSecondaryOutputs(
346             const TrackSecondaryOutputsMap& trackSecondaryOutputs) = 0;
347 };
348 
349 /**
350  * A client-side adapter, wrapping an IAudioFlingerService instance and presenting it as an
351  * IAudioFlinger. Intended to be used by legacy client code that was written against IAudioFlinger,
352  * before IAudioFlingerService was introduced as an AIDL service.
353  * New clients should not use this adapter, but rather IAudioFlingerService directly, via
354  * BpAudioFlingerService.
355  */
356 class AudioFlingerClientAdapter : public IAudioFlinger {
357 public:
358     explicit AudioFlingerClientAdapter(const sp<media::IAudioFlingerService> delegate);
359 
360     status_t createTrack(const media::CreateTrackRequest& input,
361                          media::CreateTrackResponse& output) override;
362     status_t createRecord(const media::CreateRecordRequest& input,
363                           media::CreateRecordResponse& output) override;
364     uint32_t sampleRate(audio_io_handle_t ioHandle) const override;
365     audio_format_t format(audio_io_handle_t output) const override;
366     size_t frameCount(audio_io_handle_t ioHandle) const override;
367     uint32_t latency(audio_io_handle_t output) const override;
368     status_t setMasterVolume(float value) override;
369     status_t setMasterMute(bool muted) override;
370     float masterVolume() const override;
371     bool masterMute() const override;
372     status_t setMasterBalance(float balance) override;
373     status_t getMasterBalance(float* balance) const override;
374     status_t setStreamVolume(audio_stream_type_t stream, float value,
375                              audio_io_handle_t output) override;
376     status_t setStreamMute(audio_stream_type_t stream, bool muted) override;
377     float streamVolume(audio_stream_type_t stream,
378                        audio_io_handle_t output) const override;
379     bool streamMute(audio_stream_type_t stream) const override;
380     status_t setMode(audio_mode_t mode) override;
381     status_t setMicMute(bool state) override;
382     bool getMicMute() const override;
383     void setRecordSilenced(audio_port_handle_t portId, bool silenced) override;
384     status_t setParameters(audio_io_handle_t ioHandle,
385                            const String8& keyValuePairs) override;
386     String8 getParameters(audio_io_handle_t ioHandle, const String8& keys)
387     const override;
388     void registerClient(const sp<media::IAudioFlingerClient>& client) override;
389     size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
390                               audio_channel_mask_t channelMask) const override;
391     status_t openOutput(const media::OpenOutputRequest& request,
392                         media::OpenOutputResponse* response) override;
393     audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
394                                           audio_io_handle_t output2) override;
395     status_t closeOutput(audio_io_handle_t output) override;
396     status_t suspendOutput(audio_io_handle_t output) override;
397     status_t restoreOutput(audio_io_handle_t output) override;
398     status_t openInput(const media::OpenInputRequest& request,
399                        media::OpenInputResponse* response) override;
400     status_t closeInput(audio_io_handle_t input) override;
401     status_t invalidateStream(audio_stream_type_t stream) override;
402     status_t setVoiceVolume(float volume) override;
403     status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames,
404                                audio_io_handle_t output) const override;
405     uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const override;
406     audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use) override;
407     void acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) override;
408     void releaseAudioSessionId(audio_session_t audioSession, pid_t pid) override;
409     status_t queryNumberEffects(uint32_t* numEffects) const override;
410     status_t queryEffect(uint32_t index, effect_descriptor_t* pDescriptor) const override;
411     status_t getEffectDescriptor(const effect_uuid_t* pEffectUUID,
412                                  const effect_uuid_t* pTypeUUID,
413                                  uint32_t preferredTypeFlag,
414                                  effect_descriptor_t* pDescriptor) const override;
415     status_t createEffect(const media::CreateEffectRequest& request,
416                           media::CreateEffectResponse* response) override;
417     status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
418                          audio_io_handle_t dstOutput) override;
419     void setEffectSuspended(int effectId,
420                             audio_session_t sessionId,
421                             bool suspended) override;
422     audio_module_handle_t loadHwModule(const char* name) override;
423     uint32_t getPrimaryOutputSamplingRate() override;
424     size_t getPrimaryOutputFrameCount() override;
425     status_t setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) override;
426     status_t getAudioPort(struct audio_port_v7* port) override;
427     status_t createAudioPatch(const struct audio_patch* patch,
428                               audio_patch_handle_t* handle) override;
429     status_t releaseAudioPatch(audio_patch_handle_t handle) override;
430     status_t listAudioPatches(unsigned int* num_patches,
431                               struct audio_patch* patches) override;
432     status_t setAudioPortConfig(const struct audio_port_config* config) override;
433     audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId) override;
434     status_t systemReady() override;
435     size_t frameCountHAL(audio_io_handle_t ioHandle) const override;
436     status_t getMicrophones(std::vector<media::MicrophoneInfo>* microphones) override;
437     status_t setAudioHalPids(const std::vector<pid_t>& pids) override;
438     status_t setVibratorInfos(const std::vector<media::AudioVibratorInfo>& vibratorInfos) override;
439     status_t updateSecondaryOutputs(
440             const TrackSecondaryOutputsMap& trackSecondaryOutputs) override;
441 
442 private:
443     const sp<media::IAudioFlingerService> mDelegate;
444 };
445 
446 /**
447  * A server-side adapter, wrapping an IAudioFlinger instance and presenting it as an
448  * IAudioFlingerService. Intended to be used by legacy server code that was written against
449  * IAudioFlinger, before IAudioFlingerService was introduced as an AIDL service.
450  * New servers should not use this adapter, but rather implement IAudioFlingerService directly, via
451  * BnAudioFlingerService.
452  */
453 class AudioFlingerServerAdapter : public media::BnAudioFlingerService {
454 public:
455     using Status = binder::Status;
456 
457     /**
458      * Legacy server should implement this interface in order to be wrapped.
459      */
460     class Delegate : public IAudioFlinger {
461     protected:
462         friend class AudioFlingerServerAdapter;
463 
464         enum class TransactionCode {
465             CREATE_TRACK = media::BnAudioFlingerService::TRANSACTION_createTrack,
466             CREATE_RECORD = media::BnAudioFlingerService::TRANSACTION_createRecord,
467             SAMPLE_RATE = media::BnAudioFlingerService::TRANSACTION_sampleRate,
468             FORMAT = media::BnAudioFlingerService::TRANSACTION_format,
469             FRAME_COUNT = media::BnAudioFlingerService::TRANSACTION_frameCount,
470             LATENCY = media::BnAudioFlingerService::TRANSACTION_latency,
471             SET_MASTER_VOLUME = media::BnAudioFlingerService::TRANSACTION_setMasterVolume,
472             SET_MASTER_MUTE = media::BnAudioFlingerService::TRANSACTION_setMasterMute,
473             MASTER_VOLUME = media::BnAudioFlingerService::TRANSACTION_masterVolume,
474             MASTER_MUTE = media::BnAudioFlingerService::TRANSACTION_masterMute,
475             SET_STREAM_VOLUME = media::BnAudioFlingerService::TRANSACTION_setStreamVolume,
476             SET_STREAM_MUTE = media::BnAudioFlingerService::TRANSACTION_setStreamMute,
477             STREAM_VOLUME = media::BnAudioFlingerService::TRANSACTION_streamVolume,
478             STREAM_MUTE = media::BnAudioFlingerService::TRANSACTION_streamMute,
479             SET_MODE = media::BnAudioFlingerService::TRANSACTION_setMode,
480             SET_MIC_MUTE = media::BnAudioFlingerService::TRANSACTION_setMicMute,
481             GET_MIC_MUTE = media::BnAudioFlingerService::TRANSACTION_getMicMute,
482             SET_RECORD_SILENCED = media::BnAudioFlingerService::TRANSACTION_setRecordSilenced,
483             SET_PARAMETERS = media::BnAudioFlingerService::TRANSACTION_setParameters,
484             GET_PARAMETERS = media::BnAudioFlingerService::TRANSACTION_getParameters,
485             REGISTER_CLIENT = media::BnAudioFlingerService::TRANSACTION_registerClient,
486             GET_INPUTBUFFERSIZE = media::BnAudioFlingerService::TRANSACTION_getInputBufferSize,
487             OPEN_OUTPUT = media::BnAudioFlingerService::TRANSACTION_openOutput,
488             OPEN_DUPLICATE_OUTPUT = media::BnAudioFlingerService::TRANSACTION_openDuplicateOutput,
489             CLOSE_OUTPUT = media::BnAudioFlingerService::TRANSACTION_closeOutput,
490             SUSPEND_OUTPUT = media::BnAudioFlingerService::TRANSACTION_suspendOutput,
491             RESTORE_OUTPUT = media::BnAudioFlingerService::TRANSACTION_restoreOutput,
492             OPEN_INPUT = media::BnAudioFlingerService::TRANSACTION_openInput,
493             CLOSE_INPUT = media::BnAudioFlingerService::TRANSACTION_closeInput,
494             INVALIDATE_STREAM = media::BnAudioFlingerService::TRANSACTION_invalidateStream,
495             SET_VOICE_VOLUME = media::BnAudioFlingerService::TRANSACTION_setVoiceVolume,
496             GET_RENDER_POSITION = media::BnAudioFlingerService::TRANSACTION_getRenderPosition,
497             GET_INPUT_FRAMES_LOST = media::BnAudioFlingerService::TRANSACTION_getInputFramesLost,
498             NEW_AUDIO_UNIQUE_ID = media::BnAudioFlingerService::TRANSACTION_newAudioUniqueId,
499             ACQUIRE_AUDIO_SESSION_ID = media::BnAudioFlingerService::TRANSACTION_acquireAudioSessionId,
500             RELEASE_AUDIO_SESSION_ID = media::BnAudioFlingerService::TRANSACTION_releaseAudioSessionId,
501             QUERY_NUM_EFFECTS = media::BnAudioFlingerService::TRANSACTION_queryNumberEffects,
502             QUERY_EFFECT = media::BnAudioFlingerService::TRANSACTION_queryEffect,
503             GET_EFFECT_DESCRIPTOR = media::BnAudioFlingerService::TRANSACTION_getEffectDescriptor,
504             CREATE_EFFECT = media::BnAudioFlingerService::TRANSACTION_createEffect,
505             MOVE_EFFECTS = media::BnAudioFlingerService::TRANSACTION_moveEffects,
506             LOAD_HW_MODULE = media::BnAudioFlingerService::TRANSACTION_loadHwModule,
507             GET_PRIMARY_OUTPUT_SAMPLING_RATE = media::BnAudioFlingerService::TRANSACTION_getPrimaryOutputSamplingRate,
508             GET_PRIMARY_OUTPUT_FRAME_COUNT = media::BnAudioFlingerService::TRANSACTION_getPrimaryOutputFrameCount,
509             SET_LOW_RAM_DEVICE = media::BnAudioFlingerService::TRANSACTION_setLowRamDevice,
510             GET_AUDIO_PORT = media::BnAudioFlingerService::TRANSACTION_getAudioPort,
511             CREATE_AUDIO_PATCH = media::BnAudioFlingerService::TRANSACTION_createAudioPatch,
512             RELEASE_AUDIO_PATCH = media::BnAudioFlingerService::TRANSACTION_releaseAudioPatch,
513             LIST_AUDIO_PATCHES = media::BnAudioFlingerService::TRANSACTION_listAudioPatches,
514             SET_AUDIO_PORT_CONFIG = media::BnAudioFlingerService::TRANSACTION_setAudioPortConfig,
515             GET_AUDIO_HW_SYNC_FOR_SESSION = media::BnAudioFlingerService::TRANSACTION_getAudioHwSyncForSession,
516             SYSTEM_READY = media::BnAudioFlingerService::TRANSACTION_systemReady,
517             FRAME_COUNT_HAL = media::BnAudioFlingerService::TRANSACTION_frameCountHAL,
518             GET_MICROPHONES = media::BnAudioFlingerService::TRANSACTION_getMicrophones,
519             SET_MASTER_BALANCE = media::BnAudioFlingerService::TRANSACTION_setMasterBalance,
520             GET_MASTER_BALANCE = media::BnAudioFlingerService::TRANSACTION_getMasterBalance,
521             SET_EFFECT_SUSPENDED = media::BnAudioFlingerService::TRANSACTION_setEffectSuspended,
522             SET_AUDIO_HAL_PIDS = media::BnAudioFlingerService::TRANSACTION_setAudioHalPids,
523             SET_VIBRATOR_INFOS = media::BnAudioFlingerService::TRANSACTION_setVibratorInfos,
524             UPDATE_SECONDARY_OUTPUTS = media::BnAudioFlingerService::TRANSACTION_updateSecondaryOutputs,
525         };
526 
527         /**
528          * And optional hook, called on every transaction, allowing additional operations to be
529          * performed before/after the unparceling  ofthe data and dispatching to the respective
530          * method. Useful for bulk operations, such as logging or permission checks.
531          * The implementer is responsible to invoke the provided delegate function, which is the
532          * actual onTransact(), unless an error occurs.
533          * By default, this is just a pass-through to the delegate.
534          */
onTransactWrapper(TransactionCode code,const Parcel & data,uint32_t flags,const std::function<status_t ()> & delegate)535         virtual status_t onTransactWrapper(TransactionCode code,
536                                            const Parcel& data,
537                                            uint32_t flags,
538                                            const std::function<status_t()>& delegate) {
539             (void) code;
540             (void) data;
541             (void) flags;
542             return delegate();
543         }
544 
545         /**
546          * An optional hook for implementing diagnostics dumping.
547          */
dump(int fd,const Vector<String16> & args)548         virtual status_t dump(int fd, const Vector<String16>& args) {
549             (void) fd;
550             (void) args;
551             return OK;
552         }
553     };
554 
555     explicit AudioFlingerServerAdapter(
556             const sp<AudioFlingerServerAdapter::Delegate>& delegate);
557 
558     status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) override;
559     status_t dump(int fd, const Vector<String16>& args) override;
560 
561     Status createTrack(const media::CreateTrackRequest& request,
562                        media::CreateTrackResponse* _aidl_return) override;
563     Status createRecord(const media::CreateRecordRequest& request,
564                         media::CreateRecordResponse* _aidl_return) override;
565     Status sampleRate(int32_t ioHandle, int32_t* _aidl_return) override;
566     Status format(int32_t output, media::audio::common::AudioFormat* _aidl_return) override;
567     Status frameCount(int32_t ioHandle, int64_t* _aidl_return) override;
568     Status latency(int32_t output, int32_t* _aidl_return) override;
569     Status setMasterVolume(float value) override;
570     Status setMasterMute(bool muted) override;
571     Status masterVolume(float* _aidl_return) override;
572     Status masterMute(bool* _aidl_return) override;
573     Status setMasterBalance(float balance) override;
574     Status getMasterBalance(float* _aidl_return) override;
575     Status setStreamVolume(media::AudioStreamType stream, float value, int32_t output) override;
576     Status setStreamMute(media::AudioStreamType stream, bool muted) override;
577     Status
578     streamVolume(media::AudioStreamType stream, int32_t output, float* _aidl_return) override;
579     Status streamMute(media::AudioStreamType stream, bool* _aidl_return) override;
580     Status setMode(media::AudioMode mode) override;
581     Status setMicMute(bool state) override;
582     Status getMicMute(bool* _aidl_return) override;
583     Status setRecordSilenced(int32_t portId, bool silenced) override;
584     Status setParameters(int32_t ioHandle, const std::string& keyValuePairs) override;
585     Status
586     getParameters(int32_t ioHandle, const std::string& keys, std::string* _aidl_return) override;
587     Status registerClient(const sp<media::IAudioFlingerClient>& client) override;
588     Status getInputBufferSize(int32_t sampleRate, media::audio::common::AudioFormat format,
589                               int32_t channelMask, int64_t* _aidl_return) override;
590     Status openOutput(const media::OpenOutputRequest& request,
591                       media::OpenOutputResponse* _aidl_return) override;
592     Status openDuplicateOutput(int32_t output1, int32_t output2, int32_t* _aidl_return) override;
593     Status closeOutput(int32_t output) override;
594     Status suspendOutput(int32_t output) override;
595     Status restoreOutput(int32_t output) override;
596     Status openInput(const media::OpenInputRequest& request,
597                      media::OpenInputResponse* _aidl_return) override;
598     Status closeInput(int32_t input) override;
599     Status invalidateStream(media::AudioStreamType stream) override;
600     Status setVoiceVolume(float volume) override;
601     Status getRenderPosition(int32_t output, media::RenderPosition* _aidl_return) override;
602     Status getInputFramesLost(int32_t ioHandle, int32_t* _aidl_return) override;
603     Status newAudioUniqueId(media::AudioUniqueIdUse use, int32_t* _aidl_return) override;
604     Status acquireAudioSessionId(int32_t audioSession, int32_t pid, int32_t uid) override;
605     Status releaseAudioSessionId(int32_t audioSession, int32_t pid) override;
606     Status queryNumberEffects(int32_t* _aidl_return) override;
607     Status queryEffect(int32_t index, media::EffectDescriptor* _aidl_return) override;
608     Status getEffectDescriptor(const media::AudioUuid& effectUUID, const media::AudioUuid& typeUUID,
609                                int32_t preferredTypeFlag,
610                                media::EffectDescriptor* _aidl_return) override;
611     Status createEffect(const media::CreateEffectRequest& request,
612                         media::CreateEffectResponse* _aidl_return) override;
613     Status moveEffects(int32_t session, int32_t srcOutput, int32_t dstOutput) override;
614     Status setEffectSuspended(int32_t effectId, int32_t sessionId, bool suspended) override;
615     Status loadHwModule(const std::string& name, int32_t* _aidl_return) override;
616     Status getPrimaryOutputSamplingRate(int32_t* _aidl_return) override;
617     Status getPrimaryOutputFrameCount(int64_t* _aidl_return) override;
618     Status setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) override;
619     Status getAudioPort(const media::AudioPort& port, media::AudioPort* _aidl_return) override;
620     Status createAudioPatch(const media::AudioPatch& patch, int32_t* _aidl_return) override;
621     Status releaseAudioPatch(int32_t handle) override;
622     Status listAudioPatches(int32_t maxCount,
623                             std::vector<media::AudioPatch>* _aidl_return) override;
624     Status setAudioPortConfig(const media::AudioPortConfig& config) override;
625     Status getAudioHwSyncForSession(int32_t sessionId, int32_t* _aidl_return) override;
626     Status systemReady() override;
627     Status frameCountHAL(int32_t ioHandle, int64_t* _aidl_return) override;
628     Status getMicrophones(std::vector<media::MicrophoneInfoData>* _aidl_return) override;
629     Status setAudioHalPids(const std::vector<int32_t>& pids) override;
630     Status setVibratorInfos(const std::vector<media::AudioVibratorInfo>& vibratorInfos) override;
631     Status updateSecondaryOutputs(
632             const std::vector<media::TrackSecondaryOutputInfo>& trackSecondaryOutputInfos) override;
633 
634 private:
635     const sp<AudioFlingerServerAdapter::Delegate> mDelegate;
636 };
637 
638 }; // namespace android
639 
640 #endif // ANDROID_IAUDIOFLINGER_H
641