1 /*
2  * Copyright (C) 2008 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_AUDIOSYSTEM_H_
18 #define ANDROID_AUDIOSYSTEM_H_
19 
20 #include <sys/types.h>
21 
22 #include <media/AudioDeviceTypeAddr.h>
23 #include <media/AudioPolicy.h>
24 #include <media/AudioProductStrategy.h>
25 #include <media/AudioVolumeGroup.h>
26 #include <media/AudioIoDescriptor.h>
27 #include <media/IAudioFlingerClient.h>
28 #include <media/IAudioPolicyServiceClient.h>
29 #include <media/MicrophoneInfo.h>
30 #include <system/audio.h>
31 #include <system/audio_effect.h>
32 #include <system/audio_policy.h>
33 #include <utils/Errors.h>
34 #include <utils/Mutex.h>
35 #include <vector>
36 
37 namespace android {
38 
39 typedef void (*audio_error_callback)(status_t err);
40 typedef void (*dynamic_policy_callback)(int event, String8 regId, int val);
41 typedef void (*record_config_callback)(int event,
42                                        const record_client_info_t *clientInfo,
43                                        const audio_config_base_t *clientConfig,
44                                        std::vector<effect_descriptor_t> clientEffects,
45                                        const audio_config_base_t *deviceConfig,
46                                        std::vector<effect_descriptor_t> effects,
47                                        audio_patch_handle_t patchHandle,
48                                        audio_source_t source);
49 
50 class IAudioFlinger;
51 class IAudioPolicyService;
52 class String8;
53 
54 class AudioSystem
55 {
56 public:
57 
58     // FIXME Declare in binder opcode order, similarly to IAudioFlinger.h and IAudioFlinger.cpp
59 
60     /* These are static methods to control the system-wide AudioFlinger
61      * only privileged processes can have access to them
62      */
63 
64     // mute/unmute microphone
65     static status_t muteMicrophone(bool state);
66     static status_t isMicrophoneMuted(bool *state);
67 
68     // set/get master volume
69     static status_t setMasterVolume(float value);
70     static status_t getMasterVolume(float* volume);
71 
72     // mute/unmute audio outputs
73     static status_t setMasterMute(bool mute);
74     static status_t getMasterMute(bool* mute);
75 
76     // set/get stream volume on specified output
77     static status_t setStreamVolume(audio_stream_type_t stream, float value,
78                                     audio_io_handle_t output);
79     static status_t getStreamVolume(audio_stream_type_t stream, float* volume,
80                                     audio_io_handle_t output);
81 
82     // mute/unmute stream
83     static status_t setStreamMute(audio_stream_type_t stream, bool mute);
84     static status_t getStreamMute(audio_stream_type_t stream, bool* mute);
85 
86     // set audio mode in audio hardware
87     static status_t setMode(audio_mode_t mode);
88 
89     // returns true in *state if tracks are active on the specified stream or have been active
90     // in the past inPastMs milliseconds
91     static status_t isStreamActive(audio_stream_type_t stream, bool *state, uint32_t inPastMs);
92     // returns true in *state if tracks are active for what qualifies as remote playback
93     // on the specified stream or have been active in the past inPastMs milliseconds. Remote
94     // playback isn't mutually exclusive with local playback.
95     static status_t isStreamActiveRemotely(audio_stream_type_t stream, bool *state,
96             uint32_t inPastMs);
97     // returns true in *state if a recorder is currently recording with the specified source
98     static status_t isSourceActive(audio_source_t source, bool *state);
99 
100     // set/get audio hardware parameters. The function accepts a list of parameters
101     // key value pairs in the form: key1=value1;key2=value2;...
102     // Some keys are reserved for standard parameters (See AudioParameter class).
103     // The versions with audio_io_handle_t are intended for internal media framework use only.
104     static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs);
105     static String8  getParameters(audio_io_handle_t ioHandle, const String8& keys);
106     // The versions without audio_io_handle_t are intended for JNI.
107     static status_t setParameters(const String8& keyValuePairs);
108     static String8  getParameters(const String8& keys);
109 
110     static void setErrorCallback(audio_error_callback cb);
111     static void setDynPolicyCallback(dynamic_policy_callback cb);
112     static void setRecordConfigCallback(record_config_callback);
113 
114     // helper function to obtain AudioFlinger service handle
115     static const sp<IAudioFlinger> get_audio_flinger();
116 
117     static float linearToLog(int volume);
118     static int logToLinear(float volume);
119     static size_t calculateMinFrameCount(
120             uint32_t afLatencyMs, uint32_t afFrameCount, uint32_t afSampleRate,
121             uint32_t sampleRate, float speed /*, uint32_t notificationsPerBufferReq*/);
122 
123     // Returned samplingRate and frameCount output values are guaranteed
124     // to be non-zero if status == NO_ERROR
125     // FIXME This API assumes a route, and so should be deprecated.
126     static status_t getOutputSamplingRate(uint32_t* samplingRate,
127             audio_stream_type_t stream);
128     // FIXME This API assumes a route, and so should be deprecated.
129     static status_t getOutputFrameCount(size_t* frameCount,
130             audio_stream_type_t stream);
131     // FIXME This API assumes a route, and so should be deprecated.
132     static status_t getOutputLatency(uint32_t* latency,
133             audio_stream_type_t stream);
134     // returns the audio HAL sample rate
135     static status_t getSamplingRate(audio_io_handle_t ioHandle,
136                                           uint32_t* samplingRate);
137     // For output threads with a fast mixer, returns the number of frames per normal mixer buffer.
138     // For output threads without a fast mixer, or for input, this is same as getFrameCountHAL().
139     static status_t getFrameCount(audio_io_handle_t ioHandle,
140                                   size_t* frameCount);
141     // returns the audio output latency in ms. Corresponds to
142     // audio_stream_out->get_latency()
143     static status_t getLatency(audio_io_handle_t output,
144                                uint32_t* latency);
145 
146     // return status NO_ERROR implies *buffSize > 0
147     // FIXME This API assumes a route, and so should deprecated.
148     static status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
149         audio_channel_mask_t channelMask, size_t* buffSize);
150 
151     static status_t setVoiceVolume(float volume);
152 
153     // return the number of audio frames written by AudioFlinger to audio HAL and
154     // audio dsp to DAC since the specified output has exited standby.
155     // returned status (from utils/Errors.h) can be:
156     // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data
157     // - INVALID_OPERATION: Not supported on current hardware platform
158     // - BAD_VALUE: invalid parameter
159     // NOTE: this feature is not supported on all hardware platforms and it is
160     // necessary to check returned status before using the returned values.
161     static status_t getRenderPosition(audio_io_handle_t output,
162                                       uint32_t *halFrames,
163                                       uint32_t *dspFrames);
164 
165     // return the number of input frames lost by HAL implementation, or 0 if the handle is invalid
166     static uint32_t getInputFramesLost(audio_io_handle_t ioHandle);
167 
168     // Allocate a new unique ID for use as an audio session ID or I/O handle.
169     // If unable to contact AudioFlinger, returns AUDIO_UNIQUE_ID_ALLOCATE instead.
170     // FIXME If AudioFlinger were to ever exhaust the unique ID namespace,
171     //       this method could fail by returning either a reserved ID like AUDIO_UNIQUE_ID_ALLOCATE
172     //       or an unspecified existing unique ID.
173     static audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use);
174 
175     static void acquireAudioSessionId(audio_session_t audioSession, pid_t pid);
176     static void releaseAudioSessionId(audio_session_t audioSession, pid_t pid);
177 
178     // Get the HW synchronization source used for an audio session.
179     // Return a valid source or AUDIO_HW_SYNC_INVALID if an error occurs
180     // or no HW sync source is used.
181     static audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId);
182 
183     // Indicate JAVA services are ready (scheduling, power management ...)
184     static status_t systemReady();
185 
186     // Returns the number of frames per audio HAL buffer.
187     // Corresponds to audio_stream->get_buffer_size()/audio_stream_in_frame_size() for input.
188     // See also getFrameCount().
189     static status_t getFrameCountHAL(audio_io_handle_t ioHandle,
190                                      size_t* frameCount);
191 
192     // Events used to synchronize actions between audio sessions.
193     // For instance SYNC_EVENT_PRESENTATION_COMPLETE can be used to delay recording start until
194     // playback is complete on another audio session.
195     // See definitions in MediaSyncEvent.java
196     enum sync_event_t {
197         SYNC_EVENT_SAME = -1,             // used internally to indicate restart with same event
198         SYNC_EVENT_NONE = 0,
199         SYNC_EVENT_PRESENTATION_COMPLETE,
200 
201         //
202         // Define new events here: SYNC_EVENT_START, SYNC_EVENT_STOP, SYNC_EVENT_TIME ...
203         //
204         SYNC_EVENT_CNT,
205     };
206 
207     // Timeout for synchronous record start. Prevents from blocking the record thread forever
208     // if the trigger event is not fired.
209     static const uint32_t kSyncRecordStartTimeOutMs = 30000;
210 
211     //
212     // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
213     //
214     static void onNewAudioModulesAvailable();
215     static status_t setDeviceConnectionState(audio_devices_t device, audio_policy_dev_state_t state,
216                                              const char *device_address, const char *device_name,
217                                              audio_format_t encodedFormat);
218     static audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
219                                                                 const char *device_address);
220     static status_t handleDeviceConfigChange(audio_devices_t device,
221                                              const char *device_address,
222                                              const char *device_name,
223                                              audio_format_t encodedFormat);
224     static status_t setPhoneState(audio_mode_t state);
225     static status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
226     static audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage);
227 
228     static status_t getOutputForAttr(audio_attributes_t *attr,
229                                      audio_io_handle_t *output,
230                                      audio_session_t session,
231                                      audio_stream_type_t *stream,
232                                      pid_t pid,
233                                      uid_t uid,
234                                      const audio_config_t *config,
235                                      audio_output_flags_t flags,
236                                      audio_port_handle_t *selectedDeviceId,
237                                      audio_port_handle_t *portId,
238                                      std::vector<audio_io_handle_t> *secondaryOutputs);
239     static status_t startOutput(audio_port_handle_t portId);
240     static status_t stopOutput(audio_port_handle_t portId);
241     static void releaseOutput(audio_port_handle_t portId);
242 
243     // Client must successfully hand off the handle reference to AudioFlinger via createRecord(),
244     // or release it with releaseInput().
245     static status_t getInputForAttr(const audio_attributes_t *attr,
246                                     audio_io_handle_t *input,
247                                     audio_unique_id_t riid,
248                                     audio_session_t session,
249                                     pid_t pid,
250                                     uid_t uid,
251                                     const String16& opPackageName,
252                                     const audio_config_base_t *config,
253                                     audio_input_flags_t flags,
254                                     audio_port_handle_t *selectedDeviceId,
255                                     audio_port_handle_t *portId);
256 
257     static status_t startInput(audio_port_handle_t portId);
258     static status_t stopInput(audio_port_handle_t portId);
259     static void releaseInput(audio_port_handle_t portId);
260     static status_t initStreamVolume(audio_stream_type_t stream,
261                                       int indexMin,
262                                       int indexMax);
263     static status_t setStreamVolumeIndex(audio_stream_type_t stream,
264                                          int index,
265                                          audio_devices_t device);
266     static status_t getStreamVolumeIndex(audio_stream_type_t stream,
267                                          int *index,
268                                          audio_devices_t device);
269 
270     static status_t setVolumeIndexForAttributes(const audio_attributes_t &attr,
271                                                 int index,
272                                                 audio_devices_t device);
273     static status_t getVolumeIndexForAttributes(const audio_attributes_t &attr,
274                                                 int &index,
275                                                 audio_devices_t device);
276 
277     static status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index);
278 
279     static status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index);
280 
281     static uint32_t getStrategyForStream(audio_stream_type_t stream);
282     static audio_devices_t getDevicesForStream(audio_stream_type_t stream);
283 
284     static audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
285     static status_t registerEffect(const effect_descriptor_t *desc,
286                                     audio_io_handle_t io,
287                                     uint32_t strategy,
288                                     audio_session_t session,
289                                     int id);
290     static status_t unregisterEffect(int id);
291     static status_t setEffectEnabled(int id, bool enabled);
292     static status_t moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io);
293 
294     // clear stream to output mapping cache (gStreamOutputMap)
295     // and output configuration cache (gOutputs)
296     static void clearAudioConfigCache();
297 
298     static const sp<IAudioPolicyService> get_audio_policy_service();
299 
300     // helpers for android.media.AudioManager.getProperty(), see description there for meaning
301     static uint32_t getPrimaryOutputSamplingRate();
302     static size_t getPrimaryOutputFrameCount();
303 
304     static status_t setLowRamDevice(bool isLowRamDevice, int64_t totalMemory);
305 
306     static status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags);
307 
308     // Check if hw offload is possible for given format, stream type, sample rate,
309     // bit rate, duration, video and streaming or offload property is enabled
310     static bool isOffloadSupported(const audio_offload_info_t& info);
311 
312     // check presence of audio flinger service.
313     // returns NO_ERROR if binding to service succeeds, DEAD_OBJECT otherwise
314     static status_t checkAudioFlinger();
315 
316     /* List available audio ports and their attributes */
317     static status_t listAudioPorts(audio_port_role_t role,
318                                    audio_port_type_t type,
319                                    unsigned int *num_ports,
320                                    struct audio_port *ports,
321                                    unsigned int *generation);
322 
323     /* Get attributes for a given audio port */
324     static status_t getAudioPort(struct audio_port *port);
325 
326     /* Create an audio patch between several source and sink ports */
327     static status_t createAudioPatch(const struct audio_patch *patch,
328                                        audio_patch_handle_t *handle);
329 
330     /* Release an audio patch */
331     static status_t releaseAudioPatch(audio_patch_handle_t handle);
332 
333     /* List existing audio patches */
334     static status_t listAudioPatches(unsigned int *num_patches,
335                                       struct audio_patch *patches,
336                                       unsigned int *generation);
337     /* Set audio port configuration */
338     static status_t setAudioPortConfig(const struct audio_port_config *config);
339 
340 
341     static status_t acquireSoundTriggerSession(audio_session_t *session,
342                                            audio_io_handle_t *ioHandle,
343                                            audio_devices_t *device);
344     static status_t releaseSoundTriggerSession(audio_session_t session);
345 
346     static audio_mode_t getPhoneState();
347 
348     static status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration);
349 
350     static status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices);
351 
352     static status_t removeUidDeviceAffinities(uid_t uid);
353 
354     static status_t startAudioSource(const struct audio_port_config *source,
355                                      const audio_attributes_t *attributes,
356                                      audio_port_handle_t *portId);
357     static status_t stopAudioSource(audio_port_handle_t portId);
358 
359     static status_t setMasterMono(bool mono);
360     static status_t getMasterMono(bool *mono);
361 
362     static status_t setMasterBalance(float balance);
363     static status_t getMasterBalance(float *balance);
364 
365     static float    getStreamVolumeDB(
366             audio_stream_type_t stream, int index, audio_devices_t device);
367 
368     static status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones);
369 
370     static status_t getHwOffloadEncodingFormatsSupportedForA2DP(
371                                     std::vector<audio_format_t> *formats);
372 
373     // numSurroundFormats holds the maximum number of formats and bool value allowed in the array.
374     // When numSurroundFormats is 0, surroundFormats and surroundFormatsEnabled will not be
375     // populated. The actual number of surround formats should be returned at numSurroundFormats.
376     static status_t getSurroundFormats(unsigned int *numSurroundFormats,
377                                        audio_format_t *surroundFormats,
378                                        bool *surroundFormatsEnabled,
379                                        bool reported);
380     static status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled);
381 
382     static status_t setAssistantUid(uid_t uid);
383     static status_t setA11yServicesUids(const std::vector<uid_t>& uids);
384 
385     static bool     isHapticPlaybackSupported();
386 
387     static status_t listAudioProductStrategies(AudioProductStrategyVector &strategies);
388     static status_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa,
389                                                         product_strategy_t &productStrategy);
390 
391     static audio_attributes_t streamTypeToAttributes(audio_stream_type_t stream);
392     static audio_stream_type_t attributesToStreamType(const audio_attributes_t &attr);
393 
394     static status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups);
395 
396     static status_t getVolumeGroupFromAudioAttributes(const AudioAttributes &aa,
397                                                       volume_group_t &volumeGroup);
398 
399     static status_t setRttEnabled(bool enabled);
400 
401      /**
402      * Send audio HAL server process pids to native audioserver process for use
403      * when generating audio HAL servers tombstones
404      */
405     static status_t setAudioHalPids(const std::vector<pid_t>& pids);
406 
407     static status_t setPreferredDeviceForStrategy(product_strategy_t strategy,
408             const AudioDeviceTypeAddr &device);
409 
410     static status_t removePreferredDeviceForStrategy(product_strategy_t strategy);
411 
412     static status_t getPreferredDeviceForStrategy(product_strategy_t strategy,
413             AudioDeviceTypeAddr &device);
414 
415     static status_t getDeviceForStrategy(product_strategy_t strategy,
416             AudioDeviceTypeAddr &device);
417 
418     // ----------------------------------------------------------------------------
419 
420     class AudioVolumeGroupCallback : public RefBase
421     {
422     public:
423 
AudioVolumeGroupCallback()424         AudioVolumeGroupCallback() {}
~AudioVolumeGroupCallback()425         virtual ~AudioVolumeGroupCallback() {}
426 
427         virtual void onAudioVolumeGroupChanged(volume_group_t group, int flags) = 0;
428         virtual void onServiceDied() = 0;
429 
430     };
431 
432     static status_t addAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback);
433     static status_t removeAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback);
434 
435     class AudioPortCallback : public RefBase
436     {
437     public:
438 
AudioPortCallback()439                 AudioPortCallback() {}
~AudioPortCallback()440         virtual ~AudioPortCallback() {}
441 
442         virtual void onAudioPortListUpdate() = 0;
443         virtual void onAudioPatchListUpdate() = 0;
444         virtual void onServiceDied() = 0;
445 
446     };
447 
448     static status_t addAudioPortCallback(const sp<AudioPortCallback>& callback);
449     static status_t removeAudioPortCallback(const sp<AudioPortCallback>& callback);
450 
451     class AudioDeviceCallback : public RefBase
452     {
453     public:
454 
AudioDeviceCallback()455                 AudioDeviceCallback() {}
~AudioDeviceCallback()456         virtual ~AudioDeviceCallback() {}
457 
458         virtual void onAudioDeviceUpdate(audio_io_handle_t audioIo,
459                                          audio_port_handle_t deviceId) = 0;
460     };
461 
462     static status_t addAudioDeviceCallback(const wp<AudioDeviceCallback>& callback,
463                                            audio_io_handle_t audioIo,
464                                            audio_port_handle_t portId);
465     static status_t removeAudioDeviceCallback(const wp<AudioDeviceCallback>& callback,
466                                               audio_io_handle_t audioIo,
467                                               audio_port_handle_t portId);
468 
469     static audio_port_handle_t getDeviceIdForIo(audio_io_handle_t audioIo);
470 
471 private:
472 
473     class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient
474     {
475     public:
AudioFlingerClient()476         AudioFlingerClient() :
477             mInBuffSize(0), mInSamplingRate(0),
478             mInFormat(AUDIO_FORMAT_DEFAULT), mInChannelMask(AUDIO_CHANNEL_NONE) {
479         }
480 
481         void clearIoCache();
482         status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
483                                     audio_channel_mask_t channelMask, size_t* buffSize);
484         sp<AudioIoDescriptor> getIoDescriptor(audio_io_handle_t ioHandle);
485 
486         // DeathRecipient
487         virtual void binderDied(const wp<IBinder>& who);
488 
489         // IAudioFlingerClient
490 
491         // indicate a change in the configuration of an output or input: keeps the cached
492         // values for output/input parameters up-to-date in client process
493         virtual void ioConfigChanged(audio_io_config_event event,
494                                      const sp<AudioIoDescriptor>& ioDesc);
495 
496 
497         status_t addAudioDeviceCallback(const wp<AudioDeviceCallback>& callback,
498                                                audio_io_handle_t audioIo,
499                                                audio_port_handle_t portId);
500         status_t removeAudioDeviceCallback(const wp<AudioDeviceCallback>& callback,
501                                            audio_io_handle_t audioIo,
502                                            audio_port_handle_t portId);
503 
504         audio_port_handle_t getDeviceIdForIo(audio_io_handle_t audioIo);
505 
506     private:
507         Mutex                               mLock;
508         DefaultKeyedVector<audio_io_handle_t, sp<AudioIoDescriptor> >   mIoDescriptors;
509 
510         std::map<audio_io_handle_t, std::map<audio_port_handle_t, wp<AudioDeviceCallback>>>
511                 mAudioDeviceCallbacks;
512         // cached values for recording getInputBufferSize() queries
513         size_t                              mInBuffSize;    // zero indicates cache is invalid
514         uint32_t                            mInSamplingRate;
515         audio_format_t                      mInFormat;
516         audio_channel_mask_t                mInChannelMask;
517         sp<AudioIoDescriptor> getIoDescriptor_l(audio_io_handle_t ioHandle);
518     };
519 
520     class AudioPolicyServiceClient: public IBinder::DeathRecipient,
521                                     public BnAudioPolicyServiceClient
522     {
523     public:
AudioPolicyServiceClient()524         AudioPolicyServiceClient() {
525         }
526 
527         int addAudioPortCallback(const sp<AudioPortCallback>& callback);
528         int removeAudioPortCallback(const sp<AudioPortCallback>& callback);
isAudioPortCbEnabled()529         bool isAudioPortCbEnabled() const { return (mAudioPortCallbacks.size() != 0); }
530 
531         int addAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback);
532         int removeAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback);
isAudioVolumeGroupCbEnabled()533         bool isAudioVolumeGroupCbEnabled() const { return (mAudioVolumeGroupCallback.size() != 0); }
534 
535         // DeathRecipient
536         virtual void binderDied(const wp<IBinder>& who);
537 
538         // IAudioPolicyServiceClient
539         virtual void onAudioPortListUpdate();
540         virtual void onAudioPatchListUpdate();
541         virtual void onAudioVolumeGroupChanged(volume_group_t group, int flags);
542         virtual void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state);
543         virtual void onRecordingConfigurationUpdate(int event,
544                                                     const record_client_info_t *clientInfo,
545                                                     const audio_config_base_t *clientConfig,
546                                                     std::vector<effect_descriptor_t> clientEffects,
547                                                     const audio_config_base_t *deviceConfig,
548                                                     std::vector<effect_descriptor_t> effects,
549                                                     audio_patch_handle_t patchHandle,
550                                                     audio_source_t source);
551 
552     private:
553         Mutex                               mLock;
554         Vector <sp <AudioPortCallback> >    mAudioPortCallbacks;
555         Vector <sp <AudioVolumeGroupCallback> > mAudioVolumeGroupCallback;
556     };
557 
558     static audio_io_handle_t getOutput(audio_stream_type_t stream);
559     static const sp<AudioFlingerClient> getAudioFlingerClient();
560     static sp<AudioIoDescriptor> getIoDescriptor(audio_io_handle_t ioHandle);
561 
562     static sp<AudioFlingerClient> gAudioFlingerClient;
563     static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient;
564     friend class AudioFlingerClient;
565     friend class AudioPolicyServiceClient;
566 
567     static Mutex gLock;      // protects gAudioFlinger and gAudioErrorCallback,
568     static Mutex gLockAPS;   // protects gAudioPolicyService and gAudioPolicyServiceClient
569     static sp<IAudioFlinger> gAudioFlinger;
570     static audio_error_callback gAudioErrorCallback;
571     static dynamic_policy_callback gDynPolicyCallback;
572     static record_config_callback gRecordConfigCallback;
573 
574     static size_t gInBuffSize;
575     // previous parameters for recording buffer size queries
576     static uint32_t gPrevInSamplingRate;
577     static audio_format_t gPrevInFormat;
578     static audio_channel_mask_t gPrevInChannelMask;
579 
580     static sp<IAudioPolicyService> gAudioPolicyService;
581 };
582 
583 };  // namespace android
584 
585 #endif  /*ANDROID_AUDIOSYSTEM_H_*/
586