blob: 09375cfe7cf5b08435c163fafee1a1ae7d2a3abe [file] [log] [blame]
Mathias Agopian65ab4712010-07-14 17:59:35 -07001/*
2 * Copyright (C) 2009 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_AUDIOPOLICYSERVICE_H
18#define ANDROID_AUDIOPOLICYSERVICE_H
19
Eric Laurent7c7f10b2011-06-17 21:29:58 -070020#include <cutils/misc.h>
21#include <cutils/config_utils.h>
Mathias Agopiane762be92013-05-09 16:26:45 -070022#include <cutils/compiler.h>
Glenn Kastend1d8f232011-07-08 09:34:50 -070023#include <utils/String8.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070024#include <utils/Vector.h>
Eric Laurent7c7f10b2011-06-17 21:29:58 -070025#include <utils/SortedVector.h>
Glenn Kastend2dcb082011-02-03 16:55:26 -080026#include <binder/BinderService.h>
Dima Zavin64760242011-05-11 14:15:23 -070027#include <system/audio.h>
Dima Zavin7394a4f2011-06-13 18:16:26 -070028#include <system/audio_policy.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070029#include <hardware/audio_policy.h>
Eric Laurent7c7f10b2011-06-17 21:29:58 -070030#include <media/IAudioPolicyService.h>
31#include <media/ToneGenerator.h>
32#include <media/AudioEffect.h>
Eric Laurentbaac1832014-12-01 17:52:59 -080033#include <media/AudioPolicy.h>
Eric Laurentdce54a12014-03-10 12:19:46 -070034#include <hardware_legacy/AudioPolicyInterface.h>
bryant_liuba2b4392014-06-11 16:49:30 +080035#include "AudioPolicyEffects.h"
Eric Laurentdce54a12014-03-10 12:19:46 -070036#include "AudioPolicyManager.h"
Dima Zavinfce7a472011-04-19 22:30:36 -070037
bryant_liuba2b4392014-06-11 16:49:30 +080038
Mathias Agopian65ab4712010-07-14 17:59:35 -070039namespace android {
40
Mathias Agopian65ab4712010-07-14 17:59:35 -070041// ----------------------------------------------------------------------------
42
Glenn Kastend2dcb082011-02-03 16:55:26 -080043class AudioPolicyService :
44 public BinderService<AudioPolicyService>,
45 public BnAudioPolicyService,
Eric Laurentde070132010-07-13 04:45:46 -070046 public IBinder::DeathRecipient
Mathias Agopian65ab4712010-07-14 17:59:35 -070047{
Glenn Kastend2dcb082011-02-03 16:55:26 -080048 friend class BinderService<AudioPolicyService>;
Mathias Agopian65ab4712010-07-14 17:59:35 -070049
50public:
Glenn Kastend2dcb082011-02-03 16:55:26 -080051 // for BinderService
Mathias Agopiane762be92013-05-09 16:26:45 -070052 static const char *getServiceName() ANDROID_API { return "media.audio_policy"; }
Mathias Agopian65ab4712010-07-14 17:59:35 -070053
54 virtual status_t dump(int fd, const Vector<String16>& args);
55
56 //
57 // BnAudioPolicyService (see AudioPolicyInterface for method descriptions)
58 //
59
Dima Zavinfce7a472011-04-19 22:30:36 -070060 virtual status_t setDeviceConnectionState(audio_devices_t device,
61 audio_policy_dev_state_t state,
Mathias Agopian65ab4712010-07-14 17:59:35 -070062 const char *device_address);
Dima Zavinfce7a472011-04-19 22:30:36 -070063 virtual audio_policy_dev_state_t getDeviceConnectionState(
64 audio_devices_t device,
Eric Laurentde070132010-07-13 04:45:46 -070065 const char *device_address);
Glenn Kastenf78aee72012-01-04 11:00:47 -080066 virtual status_t setPhoneState(audio_mode_t state);
Dima Zavinfce7a472011-04-19 22:30:36 -070067 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
68 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage);
69 virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
Mathias Agopian65ab4712010-07-14 17:59:35 -070070 uint32_t samplingRate = 0,
Glenn Kasten58f30212012-01-12 12:27:51 -080071 audio_format_t format = AUDIO_FORMAT_DEFAULT,
Glenn Kasten254af182012-07-03 14:59:05 -070072 audio_channel_mask_t channelMask = 0,
Eric Laurent0ca3cf92012-04-18 09:24:29 -070073 audio_output_flags_t flags =
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000074 AUDIO_OUTPUT_FLAG_NONE,
75 const audio_offload_info_t *offloadInfo = NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -080076 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
77 audio_io_handle_t *output,
78 audio_session_t session,
79 audio_stream_type_t *stream,
80 uint32_t samplingRate = 0,
81 audio_format_t format = AUDIO_FORMAT_DEFAULT,
82 audio_channel_mask_t channelMask = 0,
83 audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
84 const audio_offload_info_t *offloadInfo = NULL);
Eric Laurentde070132010-07-13 04:45:46 -070085 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -070086 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -080087 audio_session_t session);
Eric Laurentde070132010-07-13 04:45:46 -070088 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -070089 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -080090 audio_session_t session);
91 virtual void releaseOutput(audio_io_handle_t output,
92 audio_stream_type_t stream,
93 audio_session_t session);
Eric Laurentcaf7f482014-11-25 17:50:47 -080094 virtual status_t getInputForAttr(const audio_attributes_t *attr,
95 audio_io_handle_t *input,
96 audio_session_t session,
97 uint32_t samplingRate,
98 audio_format_t format,
99 audio_channel_mask_t channelMask,
100 audio_input_flags_t flags);
Eric Laurent4dc68062014-07-28 17:26:49 -0700101 virtual status_t startInput(audio_io_handle_t input,
102 audio_session_t session);
103 virtual status_t stopInput(audio_io_handle_t input,
104 audio_session_t session);
105 virtual void releaseInput(audio_io_handle_t input,
106 audio_session_t session);
Dima Zavinfce7a472011-04-19 22:30:36 -0700107 virtual status_t initStreamVolume(audio_stream_type_t stream,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700108 int indexMin,
109 int indexMax);
Eric Laurent83844cc2011-11-18 16:43:31 -0800110 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
111 int index,
112 audio_devices_t device);
113 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
114 int *index,
115 audio_devices_t device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700116
Dima Zavinfce7a472011-04-19 22:30:36 -0700117 virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
Eric Laurent63742522012-03-08 13:42:42 -0800118 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream);
Eric Laurentde070132010-07-13 04:45:46 -0700119
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700120 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
121 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700122 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700123 uint32_t strategy,
124 int session,
125 int id);
126 virtual status_t unregisterEffect(int id);
Eric Laurentdb7c0792011-08-10 10:37:50 -0700127 virtual status_t setEffectEnabled(int id, bool enabled);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800128 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800129 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700130 virtual bool isSourceActive(audio_source_t source) const;
Eric Laurentde070132010-07-13 04:45:46 -0700131
Eric Laurent57dae992011-07-24 13:36:09 -0700132 virtual status_t queryDefaultPreProcessing(int audioSession,
133 effect_descriptor_t *descriptors,
134 uint32_t *count);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700135 virtual status_t onTransact(
136 uint32_t code,
137 const Parcel& data,
138 Parcel* reply,
139 uint32_t flags);
140
141 // IBinder::DeathRecipient
142 virtual void binderDied(const wp<IBinder>& who);
143
Eric Laurentf5ada6e2014-10-09 17:49:00 -0700144 // RefBase
145 virtual void onFirstRef();
146
Mathias Agopian65ab4712010-07-14 17:59:35 -0700147 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700148 // Helpers for the struct audio_policy_service_ops implementation.
149 // This is used by the audio policy manager for certain operations that
150 // are implemented by the policy service.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700151 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700152 virtual void setParameters(audio_io_handle_t ioHandle,
153 const char *keyValuePairs,
154 int delayMs);
155
156 virtual status_t setStreamVolume(audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700157 float volume,
158 audio_io_handle_t output,
159 int delayMs = 0);
Dima Zavinfce7a472011-04-19 22:30:36 -0700160 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700161 virtual status_t stopTone();
162 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000163 virtual bool isOffloadSupported(const audio_offload_info_t &config);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700164
Eric Laurent203b1a12014-04-01 10:34:16 -0700165 virtual status_t listAudioPorts(audio_port_role_t role,
166 audio_port_type_t type,
167 unsigned int *num_ports,
168 struct audio_port *ports,
169 unsigned int *generation);
170 virtual status_t getAudioPort(struct audio_port *port);
171 virtual status_t createAudioPatch(const struct audio_patch *patch,
172 audio_patch_handle_t *handle);
173 virtual status_t releaseAudioPatch(audio_patch_handle_t handle);
174 virtual status_t listAudioPatches(unsigned int *num_patches,
175 struct audio_patch *patches,
176 unsigned int *generation);
177 virtual status_t setAudioPortConfig(const struct audio_port_config *config);
178
Eric Laurentb52c1522014-05-20 11:27:36 -0700179 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client);
180
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700181 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
182 audio_io_handle_t *ioHandle,
183 audio_devices_t *device);
184
185 virtual status_t releaseSoundTriggerSession(audio_session_t session);
186
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700187 virtual audio_mode_t getPhoneState();
188
Eric Laurentbaac1832014-12-01 17:52:59 -0800189 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration);
190
Eric Laurentbfb1b832013-01-07 09:53:42 -0800191 status_t doStopOutput(audio_io_handle_t output,
192 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800193 audio_session_t session);
194 void doReleaseOutput(audio_io_handle_t output,
195 audio_stream_type_t stream,
196 audio_session_t session);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800197
Eric Laurent951f4552014-05-20 10:48:17 -0700198 status_t clientCreateAudioPatch(const struct audio_patch *patch,
199 audio_patch_handle_t *handle,
200 int delayMs);
201 status_t clientReleaseAudioPatch(audio_patch_handle_t handle,
202 int delayMs);
Eric Laurente1715a42014-05-20 11:30:42 -0700203 virtual status_t clientSetAudioPortConfig(const struct audio_port_config *config,
204 int delayMs);
205
Eric Laurentb52c1522014-05-20 11:27:36 -0700206 void removeNotificationClient(uid_t uid);
207 void onAudioPortListUpdate();
208 void doOnAudioPortListUpdate();
209 void onAudioPatchListUpdate();
210 void doOnAudioPatchListUpdate();
Eric Laurent951f4552014-05-20 10:48:17 -0700211
Mathias Agopian65ab4712010-07-14 17:59:35 -0700212private:
Mathias Agopiane762be92013-05-09 16:26:45 -0700213 AudioPolicyService() ANDROID_API;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700214 virtual ~AudioPolicyService();
215
216 status_t dumpInternals(int fd);
217
218 // Thread used for tone playback and to send audio config commands to audio flinger
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700219 // For tone playback, using a separate thread is necessary to avoid deadlock with mLock because
220 // startTone() and stopTone() are normally called with mLock locked and requesting a tone start
221 // or stop will cause calls to AudioPolicyService and an attempt to lock mLock.
222 // For audio config commands, it is necessary because audio flinger requires that the calling
223 // process (user) has permission to modify audio settings.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700224 class AudioCommandThread : public Thread {
225 class AudioCommand;
226 public:
227
228 // commands for tone AudioCommand
229 enum {
230 START_TONE,
231 STOP_TONE,
232 SET_VOLUME,
233 SET_PARAMETERS,
Eric Laurentbfb1b832013-01-07 09:53:42 -0800234 SET_VOICE_VOLUME,
235 STOP_OUTPUT,
Eric Laurent951f4552014-05-20 10:48:17 -0700236 RELEASE_OUTPUT,
237 CREATE_AUDIO_PATCH,
238 RELEASE_AUDIO_PATCH,
Eric Laurentb52c1522014-05-20 11:27:36 -0700239 UPDATE_AUDIOPORT_LIST,
Eric Laurente1715a42014-05-20 11:30:42 -0700240 UPDATE_AUDIOPATCH_LIST,
241 SET_AUDIOPORT_CONFIG,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700242 };
243
Eric Laurentbfb1b832013-01-07 09:53:42 -0800244 AudioCommandThread (String8 name, const wp<AudioPolicyService>& service);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700245 virtual ~AudioCommandThread();
246
247 status_t dump(int fd);
248
249 // Thread virtuals
250 virtual void onFirstRef();
251 virtual bool threadLoop();
252
253 void exit();
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800254 void startToneCommand(ToneGenerator::tone_type type,
255 audio_stream_type_t stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700256 void stopToneCommand();
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800257 status_t volumeCommand(audio_stream_type_t stream, float volume,
258 audio_io_handle_t output, int delayMs = 0);
259 status_t parametersCommand(audio_io_handle_t ioHandle,
260 const char *keyValuePairs, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700261 status_t voiceVolumeCommand(float volume, int delayMs = 0);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800262 void stopOutputCommand(audio_io_handle_t output,
263 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800264 audio_session_t session);
265 void releaseOutputCommand(audio_io_handle_t output,
266 audio_stream_type_t stream,
267 audio_session_t session);
Eric Laurent0ede8922014-05-09 18:04:42 -0700268 status_t sendCommand(sp<AudioCommand>& command, int delayMs = 0);
269 void insertCommand_l(sp<AudioCommand>& command, int delayMs = 0);
Eric Laurent951f4552014-05-20 10:48:17 -0700270 status_t createAudioPatchCommand(const struct audio_patch *patch,
271 audio_patch_handle_t *handle,
272 int delayMs);
273 status_t releaseAudioPatchCommand(audio_patch_handle_t handle,
274 int delayMs);
Eric Laurentb52c1522014-05-20 11:27:36 -0700275 void updateAudioPortListCommand();
276 void updateAudioPatchListCommand();
Eric Laurente1715a42014-05-20 11:30:42 -0700277 status_t setAudioPortConfigCommand(const struct audio_port_config *config,
278 int delayMs);
Eric Laurent951f4552014-05-20 10:48:17 -0700279 void insertCommand_l(AudioCommand *command, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700280
281 private:
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100282 class AudioCommandData;
283
Mathias Agopian65ab4712010-07-14 17:59:35 -0700284 // descriptor for requested tone playback event
Eric Laurent0ede8922014-05-09 18:04:42 -0700285 class AudioCommand: public RefBase {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700286
287 public:
288 AudioCommand()
Eric Laurent0ede8922014-05-09 18:04:42 -0700289 : mCommand(-1), mStatus(NO_ERROR), mWaitStatus(false) {}
Mathias Agopian65ab4712010-07-14 17:59:35 -0700290
291 void dump(char* buffer, size_t size);
292
293 int mCommand; // START_TONE, STOP_TONE ...
294 nsecs_t mTime; // time stamp
Eric Laurent0ede8922014-05-09 18:04:42 -0700295 Mutex mLock; // mutex associated to mCond
Mathias Agopian65ab4712010-07-14 17:59:35 -0700296 Condition mCond; // condition for status return
297 status_t mStatus; // command status
298 bool mWaitStatus; // true if caller is waiting for status
Eric Laurent0ede8922014-05-09 18:04:42 -0700299 sp<AudioCommandData> mParam; // command specific parameter data
Mathias Agopian65ab4712010-07-14 17:59:35 -0700300 };
301
Eric Laurent0ede8922014-05-09 18:04:42 -0700302 class AudioCommandData: public RefBase {
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100303 public:
304 virtual ~AudioCommandData() {}
305 protected:
306 AudioCommandData() {}
307 };
308
309 class ToneData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700310 public:
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800311 ToneGenerator::tone_type mType; // tone type (START_TONE only)
Glenn Kastenfff6d712012-01-12 16:38:12 -0800312 audio_stream_type_t mStream; // stream type (START_TONE only)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700313 };
314
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100315 class VolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700316 public:
Glenn Kastenfff6d712012-01-12 16:38:12 -0800317 audio_stream_type_t mStream;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700318 float mVolume;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800319 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700320 };
321
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100322 class ParametersData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700323 public:
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800324 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700325 String8 mKeyValuePairs;
326 };
327
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100328 class VoiceVolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700329 public:
330 float mVolume;
331 };
332
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100333 class StopOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800334 public:
335 audio_io_handle_t mIO;
336 audio_stream_type_t mStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800337 audio_session_t mSession;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800338 };
339
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100340 class ReleaseOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800341 public:
342 audio_io_handle_t mIO;
Eric Laurente83b55d2014-11-14 10:06:21 -0800343 audio_stream_type_t mStream;
344 audio_session_t mSession;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800345 };
346
Eric Laurent951f4552014-05-20 10:48:17 -0700347 class CreateAudioPatchData : public AudioCommandData {
348 public:
349 struct audio_patch mPatch;
350 audio_patch_handle_t mHandle;
351 };
352
353 class ReleaseAudioPatchData : public AudioCommandData {
354 public:
355 audio_patch_handle_t mHandle;
356 };
357
Eric Laurente1715a42014-05-20 11:30:42 -0700358 class SetAudioPortConfigData : public AudioCommandData {
359 public:
360 struct audio_port_config mConfig;
361 };
362
Mathias Agopian65ab4712010-07-14 17:59:35 -0700363 Mutex mLock;
364 Condition mWaitWorkCV;
Eric Laurent0ede8922014-05-09 18:04:42 -0700365 Vector < sp<AudioCommand> > mAudioCommands; // list of pending commands
Mathias Agopian65ab4712010-07-14 17:59:35 -0700366 ToneGenerator *mpToneGenerator; // the tone generator
Eric Laurent0ede8922014-05-09 18:04:42 -0700367 sp<AudioCommand> mLastCommand; // last processed command (used by dump)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700368 String8 mName; // string used by wake lock fo delayed commands
Eric Laurentbfb1b832013-01-07 09:53:42 -0800369 wp<AudioPolicyService> mService;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700370 };
371
Eric Laurentdce54a12014-03-10 12:19:46 -0700372 class AudioPolicyClient : public AudioPolicyClientInterface
373 {
374 public:
375 AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {}
376 virtual ~AudioPolicyClient() {}
377
378 //
379 // Audio HW module functions
380 //
381
382 // loads a HW module.
383 virtual audio_module_handle_t loadHwModule(const char *name);
384
385 //
386 // Audio output Control functions
387 //
388
389 // opens an audio output with the requested parameters. The parameter values can indicate to use the default values
390 // in case the audio policy manager has no specific requirements for the output being opened.
391 // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream.
392 // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly.
Eric Laurentcf2c0212014-07-25 16:20:43 -0700393 virtual status_t openOutput(audio_module_handle_t module,
394 audio_io_handle_t *output,
395 audio_config_t *config,
396 audio_devices_t *devices,
397 const String8& address,
398 uint32_t *latencyMs,
399 audio_output_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700400 // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by
401 // a special mixer thread in the AudioFlinger.
402 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2);
403 // closes the output stream
404 virtual status_t closeOutput(audio_io_handle_t output);
405 // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in
406 // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded.
407 virtual status_t suspendOutput(audio_io_handle_t output);
408 // restores a suspended output.
409 virtual status_t restoreOutput(audio_io_handle_t output);
410
411 //
412 // Audio input Control functions
413 //
414
415 // opens an audio input
416 virtual audio_io_handle_t openInput(audio_module_handle_t module,
Eric Laurentcf2c0212014-07-25 16:20:43 -0700417 audio_io_handle_t *input,
418 audio_config_t *config,
419 audio_devices_t *devices,
420 const String8& address,
421 audio_source_t source,
Glenn Kastenec40d282014-07-15 15:31:26 -0700422 audio_input_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700423 // closes an audio input
424 virtual status_t closeInput(audio_io_handle_t input);
425 //
426 // misc control functions
427 //
428
429 // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes
430 // for each output (destination device) it is attached to.
431 virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0);
432
433 // invalidate a stream type, causing a reroute to an unspecified new output
434 virtual status_t invalidateStream(audio_stream_type_t stream);
435
436 // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface.
437 virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0);
438 // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager.
439 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
440
441 // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing
442 // over a telephony device during a phone call.
443 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
444 virtual status_t stopTone();
445
446 // set down link audio volume.
447 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
448
449 // move effect to the specified output
450 virtual status_t moveEffects(int session,
451 audio_io_handle_t srcOutput,
452 audio_io_handle_t dstOutput);
453
Eric Laurent951f4552014-05-20 10:48:17 -0700454 /* Create a patch between several source and sink ports */
455 virtual status_t createAudioPatch(const struct audio_patch *patch,
456 audio_patch_handle_t *handle,
457 int delayMs);
458
459 /* Release a patch */
460 virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
461 int delayMs);
462
Eric Laurente1715a42014-05-20 11:30:42 -0700463 /* Set audio port configuration */
464 virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs);
465
Eric Laurentb52c1522014-05-20 11:27:36 -0700466 virtual void onAudioPortListUpdate();
467 virtual void onAudioPatchListUpdate();
468
Eric Laurentde3f8392014-07-27 18:38:22 -0700469 virtual audio_unique_id_t newAudioUniqueId();
470
Eric Laurentdce54a12014-03-10 12:19:46 -0700471 private:
472 AudioPolicyService *mAudioPolicyService;
473 };
474
Eric Laurentb52c1522014-05-20 11:27:36 -0700475 // --- Notification Client ---
476 class NotificationClient : public IBinder::DeathRecipient {
477 public:
478 NotificationClient(const sp<AudioPolicyService>& service,
479 const sp<IAudioPolicyServiceClient>& client,
480 uid_t uid);
481 virtual ~NotificationClient();
482
483 void onAudioPortListUpdate();
484 void onAudioPatchListUpdate();
485
486 // IBinder::DeathRecipient
487 virtual void binderDied(const wp<IBinder>& who);
488
489 private:
490 NotificationClient(const NotificationClient&);
491 NotificationClient& operator = (const NotificationClient&);
492
493 const wp<AudioPolicyService> mService;
494 const uid_t mUid;
495 const sp<IAudioPolicyServiceClient> mAudioPolicyServiceClient;
496 };
497
Mathias Agopian65ab4712010-07-14 17:59:35 -0700498 // Internal dump utilities.
499 status_t dumpPermissionDenial(int fd);
500
501
Eric Laurenteda6c362011-02-02 09:33:30 -0800502 mutable Mutex mLock; // prevents concurrent access to AudioPolicy manager functions changing
503 // device connection state or routing
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700504 sp<AudioCommandThread> mAudioCommandThread; // audio commands thread
505 sp<AudioCommandThread> mTonePlaybackThread; // tone playback thread
Eric Laurentbfb1b832013-01-07 09:53:42 -0800506 sp<AudioCommandThread> mOutputCommandThread; // process stop and release output
Dima Zavinfce7a472011-04-19 22:30:36 -0700507 struct audio_policy_device *mpAudioPolicyDev;
508 struct audio_policy *mpAudioPolicy;
Eric Laurentf269b8e2014-06-09 20:01:29 -0700509 AudioPolicyInterface *mAudioPolicyManager;
Eric Laurentdce54a12014-03-10 12:19:46 -0700510 AudioPolicyClient *mAudioPolicyClient;
511
Eric Laurentb52c1522014-05-20 11:27:36 -0700512 DefaultKeyedVector< uid_t, sp<NotificationClient> > mNotificationClients;
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800513 Mutex mNotificationClientsLock; // protects mNotificationClients
bryant_liuba2b4392014-06-11 16:49:30 +0800514 // Manage all effects configured in audio_effects.conf
515 sp<AudioPolicyEffects> mAudioPolicyEffects;
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700516 audio_mode_t mPhoneState;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700517};
518
519}; // namespace android
520
521#endif // ANDROID_AUDIOPOLICYSERVICE_H