blob: a09c08486ddcb0efaf83d7aa55adb9e83a98149b [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>
Chih-Hung Hsiehc84d9d22014-11-14 13:33:34 -080033#ifdef USE_LEGACY_AUDIO_POLICY
Eric Laurentdce54a12014-03-10 12:19:46 -070034#include <hardware_legacy/AudioPolicyInterface.h>
Chih-Hung Hsiehc84d9d22014-11-14 13:33:34 -080035#endif
bryant_liuba2b4392014-06-11 16:49:30 +080036#include "AudioPolicyEffects.h"
Eric Laurentdce54a12014-03-10 12:19:46 -070037#include "AudioPolicyManager.h"
Dima Zavinfce7a472011-04-19 22:30:36 -070038
bryant_liuba2b4392014-06-11 16:49:30 +080039
Mathias Agopian65ab4712010-07-14 17:59:35 -070040namespace android {
41
Mathias Agopian65ab4712010-07-14 17:59:35 -070042// ----------------------------------------------------------------------------
43
Glenn Kastend2dcb082011-02-03 16:55:26 -080044class AudioPolicyService :
45 public BinderService<AudioPolicyService>,
46 public BnAudioPolicyService,
Eric Laurentde070132010-07-13 04:45:46 -070047 public IBinder::DeathRecipient
Mathias Agopian65ab4712010-07-14 17:59:35 -070048{
Glenn Kastend2dcb082011-02-03 16:55:26 -080049 friend class BinderService<AudioPolicyService>;
Mathias Agopian65ab4712010-07-14 17:59:35 -070050
51public:
Glenn Kastend2dcb082011-02-03 16:55:26 -080052 // for BinderService
Mathias Agopiane762be92013-05-09 16:26:45 -070053 static const char *getServiceName() ANDROID_API { return "media.audio_policy"; }
Mathias Agopian65ab4712010-07-14 17:59:35 -070054
55 virtual status_t dump(int fd, const Vector<String16>& args);
56
57 //
58 // BnAudioPolicyService (see AudioPolicyInterface for method descriptions)
59 //
60
Dima Zavinfce7a472011-04-19 22:30:36 -070061 virtual status_t setDeviceConnectionState(audio_devices_t device,
62 audio_policy_dev_state_t state,
Mathias Agopian65ab4712010-07-14 17:59:35 -070063 const char *device_address);
Dima Zavinfce7a472011-04-19 22:30:36 -070064 virtual audio_policy_dev_state_t getDeviceConnectionState(
65 audio_devices_t device,
Eric Laurentde070132010-07-13 04:45:46 -070066 const char *device_address);
Glenn Kastenf78aee72012-01-04 11:00:47 -080067 virtual status_t setPhoneState(audio_mode_t state);
Dima Zavinfce7a472011-04-19 22:30:36 -070068 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
69 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage);
70 virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
Mathias Agopian65ab4712010-07-14 17:59:35 -070071 uint32_t samplingRate = 0,
Glenn Kasten58f30212012-01-12 12:27:51 -080072 audio_format_t format = AUDIO_FORMAT_DEFAULT,
Glenn Kasten254af182012-07-03 14:59:05 -070073 audio_channel_mask_t channelMask = 0,
Eric Laurent0ca3cf92012-04-18 09:24:29 -070074 audio_output_flags_t flags =
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000075 AUDIO_OUTPUT_FLAG_NONE,
76 const audio_offload_info_t *offloadInfo = NULL);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070077 virtual audio_io_handle_t getOutputForAttr(const audio_attributes_t *attr,
78 uint32_t samplingRate = 0,
79 audio_format_t format = AUDIO_FORMAT_DEFAULT,
80 audio_channel_mask_t channelMask = 0,
81 audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
82 const audio_offload_info_t *offloadInfo = NULL);
Eric Laurentde070132010-07-13 04:45:46 -070083 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -070084 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -070085 int session = 0);
86 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -070087 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -070088 int session = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -070089 virtual void releaseOutput(audio_io_handle_t output);
Glenn Kasteneba51fb2012-01-23 13:58:49 -080090 virtual audio_io_handle_t getInput(audio_source_t inputSource,
Glenn Kastenb3b16602014-07-16 08:36:31 -070091 uint32_t samplingRate,
92 audio_format_t format,
93 audio_channel_mask_t channelMask,
94 int audioSession,
95 audio_input_flags_t flags);
Eric Laurent4dc68062014-07-28 17:26:49 -070096 virtual status_t startInput(audio_io_handle_t input,
97 audio_session_t session);
98 virtual status_t stopInput(audio_io_handle_t input,
99 audio_session_t session);
100 virtual void releaseInput(audio_io_handle_t input,
101 audio_session_t session);
Dima Zavinfce7a472011-04-19 22:30:36 -0700102 virtual status_t initStreamVolume(audio_stream_type_t stream,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700103 int indexMin,
104 int indexMax);
Eric Laurent83844cc2011-11-18 16:43:31 -0800105 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
106 int index,
107 audio_devices_t device);
108 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
109 int *index,
110 audio_devices_t device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700111
Dima Zavinfce7a472011-04-19 22:30:36 -0700112 virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
Eric Laurent63742522012-03-08 13:42:42 -0800113 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream);
Eric Laurentde070132010-07-13 04:45:46 -0700114
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700115 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
116 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700117 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700118 uint32_t strategy,
119 int session,
120 int id);
121 virtual status_t unregisterEffect(int id);
Eric Laurentdb7c0792011-08-10 10:37:50 -0700122 virtual status_t setEffectEnabled(int id, bool enabled);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800123 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800124 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700125 virtual bool isSourceActive(audio_source_t source) const;
Eric Laurentde070132010-07-13 04:45:46 -0700126
Eric Laurent57dae992011-07-24 13:36:09 -0700127 virtual status_t queryDefaultPreProcessing(int audioSession,
128 effect_descriptor_t *descriptors,
129 uint32_t *count);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700130 virtual status_t onTransact(
131 uint32_t code,
132 const Parcel& data,
133 Parcel* reply,
134 uint32_t flags);
135
136 // IBinder::DeathRecipient
137 virtual void binderDied(const wp<IBinder>& who);
138
Eric Laurentf5ada6e2014-10-09 17:49:00 -0700139 // RefBase
140 virtual void onFirstRef();
141
Mathias Agopian65ab4712010-07-14 17:59:35 -0700142 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700143 // Helpers for the struct audio_policy_service_ops implementation.
144 // This is used by the audio policy manager for certain operations that
145 // are implemented by the policy service.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700146 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700147 virtual void setParameters(audio_io_handle_t ioHandle,
148 const char *keyValuePairs,
149 int delayMs);
150
151 virtual status_t setStreamVolume(audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700152 float volume,
153 audio_io_handle_t output,
154 int delayMs = 0);
Dima Zavinfce7a472011-04-19 22:30:36 -0700155 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700156 virtual status_t stopTone();
157 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000158 virtual bool isOffloadSupported(const audio_offload_info_t &config);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700159
Eric Laurent203b1a12014-04-01 10:34:16 -0700160 virtual status_t listAudioPorts(audio_port_role_t role,
161 audio_port_type_t type,
162 unsigned int *num_ports,
163 struct audio_port *ports,
164 unsigned int *generation);
165 virtual status_t getAudioPort(struct audio_port *port);
166 virtual status_t createAudioPatch(const struct audio_patch *patch,
167 audio_patch_handle_t *handle);
168 virtual status_t releaseAudioPatch(audio_patch_handle_t handle);
169 virtual status_t listAudioPatches(unsigned int *num_patches,
170 struct audio_patch *patches,
171 unsigned int *generation);
172 virtual status_t setAudioPortConfig(const struct audio_port_config *config);
173
Eric Laurentb52c1522014-05-20 11:27:36 -0700174 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client);
175
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700176 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
177 audio_io_handle_t *ioHandle,
178 audio_devices_t *device);
179
180 virtual status_t releaseSoundTriggerSession(audio_session_t session);
181
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700182 virtual audio_mode_t getPhoneState();
183
Eric Laurentbfb1b832013-01-07 09:53:42 -0800184 status_t doStopOutput(audio_io_handle_t output,
185 audio_stream_type_t stream,
186 int session = 0);
187 void doReleaseOutput(audio_io_handle_t output);
188
Eric Laurent951f4552014-05-20 10:48:17 -0700189 status_t clientCreateAudioPatch(const struct audio_patch *patch,
190 audio_patch_handle_t *handle,
191 int delayMs);
192 status_t clientReleaseAudioPatch(audio_patch_handle_t handle,
193 int delayMs);
Eric Laurente1715a42014-05-20 11:30:42 -0700194 virtual status_t clientSetAudioPortConfig(const struct audio_port_config *config,
195 int delayMs);
196
Eric Laurentb52c1522014-05-20 11:27:36 -0700197 void removeNotificationClient(uid_t uid);
198 void onAudioPortListUpdate();
199 void doOnAudioPortListUpdate();
200 void onAudioPatchListUpdate();
201 void doOnAudioPatchListUpdate();
Eric Laurent951f4552014-05-20 10:48:17 -0700202
Mathias Agopian65ab4712010-07-14 17:59:35 -0700203private:
Mathias Agopiane762be92013-05-09 16:26:45 -0700204 AudioPolicyService() ANDROID_API;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700205 virtual ~AudioPolicyService();
206
207 status_t dumpInternals(int fd);
208
209 // Thread used for tone playback and to send audio config commands to audio flinger
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700210 // For tone playback, using a separate thread is necessary to avoid deadlock with mLock because
211 // startTone() and stopTone() are normally called with mLock locked and requesting a tone start
212 // or stop will cause calls to AudioPolicyService and an attempt to lock mLock.
213 // For audio config commands, it is necessary because audio flinger requires that the calling
214 // process (user) has permission to modify audio settings.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700215 class AudioCommandThread : public Thread {
216 class AudioCommand;
217 public:
218
219 // commands for tone AudioCommand
220 enum {
221 START_TONE,
222 STOP_TONE,
223 SET_VOLUME,
224 SET_PARAMETERS,
Eric Laurentbfb1b832013-01-07 09:53:42 -0800225 SET_VOICE_VOLUME,
226 STOP_OUTPUT,
Eric Laurent951f4552014-05-20 10:48:17 -0700227 RELEASE_OUTPUT,
228 CREATE_AUDIO_PATCH,
229 RELEASE_AUDIO_PATCH,
Eric Laurentb52c1522014-05-20 11:27:36 -0700230 UPDATE_AUDIOPORT_LIST,
Eric Laurente1715a42014-05-20 11:30:42 -0700231 UPDATE_AUDIOPATCH_LIST,
232 SET_AUDIOPORT_CONFIG,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700233 };
234
Eric Laurentbfb1b832013-01-07 09:53:42 -0800235 AudioCommandThread (String8 name, const wp<AudioPolicyService>& service);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700236 virtual ~AudioCommandThread();
237
238 status_t dump(int fd);
239
240 // Thread virtuals
241 virtual void onFirstRef();
242 virtual bool threadLoop();
243
244 void exit();
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800245 void startToneCommand(ToneGenerator::tone_type type,
246 audio_stream_type_t stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700247 void stopToneCommand();
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800248 status_t volumeCommand(audio_stream_type_t stream, float volume,
249 audio_io_handle_t output, int delayMs = 0);
250 status_t parametersCommand(audio_io_handle_t ioHandle,
251 const char *keyValuePairs, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700252 status_t voiceVolumeCommand(float volume, int delayMs = 0);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800253 void stopOutputCommand(audio_io_handle_t output,
254 audio_stream_type_t stream,
255 int session);
256 void releaseOutputCommand(audio_io_handle_t output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700257 status_t sendCommand(sp<AudioCommand>& command, int delayMs = 0);
258 void insertCommand_l(sp<AudioCommand>& command, int delayMs = 0);
Eric Laurent951f4552014-05-20 10:48:17 -0700259 status_t createAudioPatchCommand(const struct audio_patch *patch,
260 audio_patch_handle_t *handle,
261 int delayMs);
262 status_t releaseAudioPatchCommand(audio_patch_handle_t handle,
263 int delayMs);
Eric Laurentb52c1522014-05-20 11:27:36 -0700264 void updateAudioPortListCommand();
265 void updateAudioPatchListCommand();
Eric Laurente1715a42014-05-20 11:30:42 -0700266 status_t setAudioPortConfigCommand(const struct audio_port_config *config,
267 int delayMs);
Eric Laurent951f4552014-05-20 10:48:17 -0700268 void insertCommand_l(AudioCommand *command, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700269
270 private:
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100271 class AudioCommandData;
272
Mathias Agopian65ab4712010-07-14 17:59:35 -0700273 // descriptor for requested tone playback event
Eric Laurent0ede8922014-05-09 18:04:42 -0700274 class AudioCommand: public RefBase {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700275
276 public:
277 AudioCommand()
Eric Laurent0ede8922014-05-09 18:04:42 -0700278 : mCommand(-1), mStatus(NO_ERROR), mWaitStatus(false) {}
Mathias Agopian65ab4712010-07-14 17:59:35 -0700279
280 void dump(char* buffer, size_t size);
281
282 int mCommand; // START_TONE, STOP_TONE ...
283 nsecs_t mTime; // time stamp
Eric Laurent0ede8922014-05-09 18:04:42 -0700284 Mutex mLock; // mutex associated to mCond
Mathias Agopian65ab4712010-07-14 17:59:35 -0700285 Condition mCond; // condition for status return
286 status_t mStatus; // command status
287 bool mWaitStatus; // true if caller is waiting for status
Eric Laurent0ede8922014-05-09 18:04:42 -0700288 sp<AudioCommandData> mParam; // command specific parameter data
Mathias Agopian65ab4712010-07-14 17:59:35 -0700289 };
290
Eric Laurent0ede8922014-05-09 18:04:42 -0700291 class AudioCommandData: public RefBase {
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100292 public:
293 virtual ~AudioCommandData() {}
294 protected:
295 AudioCommandData() {}
296 };
297
298 class ToneData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700299 public:
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800300 ToneGenerator::tone_type mType; // tone type (START_TONE only)
Glenn Kastenfff6d712012-01-12 16:38:12 -0800301 audio_stream_type_t mStream; // stream type (START_TONE only)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700302 };
303
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100304 class VolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700305 public:
Glenn Kastenfff6d712012-01-12 16:38:12 -0800306 audio_stream_type_t mStream;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700307 float mVolume;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800308 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700309 };
310
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100311 class ParametersData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700312 public:
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800313 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700314 String8 mKeyValuePairs;
315 };
316
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100317 class VoiceVolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700318 public:
319 float mVolume;
320 };
321
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100322 class StopOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800323 public:
324 audio_io_handle_t mIO;
325 audio_stream_type_t mStream;
326 int mSession;
327 };
328
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100329 class ReleaseOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800330 public:
331 audio_io_handle_t mIO;
332 };
333
Eric Laurent951f4552014-05-20 10:48:17 -0700334 class CreateAudioPatchData : public AudioCommandData {
335 public:
336 struct audio_patch mPatch;
337 audio_patch_handle_t mHandle;
338 };
339
340 class ReleaseAudioPatchData : public AudioCommandData {
341 public:
342 audio_patch_handle_t mHandle;
343 };
344
Eric Laurente1715a42014-05-20 11:30:42 -0700345 class SetAudioPortConfigData : public AudioCommandData {
346 public:
347 struct audio_port_config mConfig;
348 };
349
Mathias Agopian65ab4712010-07-14 17:59:35 -0700350 Mutex mLock;
351 Condition mWaitWorkCV;
Eric Laurent0ede8922014-05-09 18:04:42 -0700352 Vector < sp<AudioCommand> > mAudioCommands; // list of pending commands
Mathias Agopian65ab4712010-07-14 17:59:35 -0700353 ToneGenerator *mpToneGenerator; // the tone generator
Eric Laurent0ede8922014-05-09 18:04:42 -0700354 sp<AudioCommand> mLastCommand; // last processed command (used by dump)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700355 String8 mName; // string used by wake lock fo delayed commands
Eric Laurentbfb1b832013-01-07 09:53:42 -0800356 wp<AudioPolicyService> mService;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700357 };
358
Eric Laurentdce54a12014-03-10 12:19:46 -0700359 class AudioPolicyClient : public AudioPolicyClientInterface
360 {
361 public:
362 AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {}
363 virtual ~AudioPolicyClient() {}
364
365 //
366 // Audio HW module functions
367 //
368
369 // loads a HW module.
370 virtual audio_module_handle_t loadHwModule(const char *name);
371
372 //
373 // Audio output Control functions
374 //
375
376 // opens an audio output with the requested parameters. The parameter values can indicate to use the default values
377 // in case the audio policy manager has no specific requirements for the output being opened.
378 // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream.
379 // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly.
Eric Laurentcf2c0212014-07-25 16:20:43 -0700380 virtual status_t openOutput(audio_module_handle_t module,
381 audio_io_handle_t *output,
382 audio_config_t *config,
383 audio_devices_t *devices,
384 const String8& address,
385 uint32_t *latencyMs,
386 audio_output_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700387 // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by
388 // a special mixer thread in the AudioFlinger.
389 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2);
390 // closes the output stream
391 virtual status_t closeOutput(audio_io_handle_t output);
392 // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in
393 // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded.
394 virtual status_t suspendOutput(audio_io_handle_t output);
395 // restores a suspended output.
396 virtual status_t restoreOutput(audio_io_handle_t output);
397
398 //
399 // Audio input Control functions
400 //
401
402 // opens an audio input
403 virtual audio_io_handle_t openInput(audio_module_handle_t module,
Eric Laurentcf2c0212014-07-25 16:20:43 -0700404 audio_io_handle_t *input,
405 audio_config_t *config,
406 audio_devices_t *devices,
407 const String8& address,
408 audio_source_t source,
Glenn Kastenec40d282014-07-15 15:31:26 -0700409 audio_input_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700410 // closes an audio input
411 virtual status_t closeInput(audio_io_handle_t input);
412 //
413 // misc control functions
414 //
415
416 // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes
417 // for each output (destination device) it is attached to.
418 virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0);
419
420 // invalidate a stream type, causing a reroute to an unspecified new output
421 virtual status_t invalidateStream(audio_stream_type_t stream);
422
423 // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface.
424 virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0);
425 // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager.
426 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
427
428 // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing
429 // over a telephony device during a phone call.
430 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
431 virtual status_t stopTone();
432
433 // set down link audio volume.
434 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
435
436 // move effect to the specified output
437 virtual status_t moveEffects(int session,
438 audio_io_handle_t srcOutput,
439 audio_io_handle_t dstOutput);
440
Eric Laurent951f4552014-05-20 10:48:17 -0700441 /* Create a patch between several source and sink ports */
442 virtual status_t createAudioPatch(const struct audio_patch *patch,
443 audio_patch_handle_t *handle,
444 int delayMs);
445
446 /* Release a patch */
447 virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
448 int delayMs);
449
Eric Laurente1715a42014-05-20 11:30:42 -0700450 /* Set audio port configuration */
451 virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs);
452
Eric Laurentb52c1522014-05-20 11:27:36 -0700453 virtual void onAudioPortListUpdate();
454 virtual void onAudioPatchListUpdate();
455
Eric Laurentde3f8392014-07-27 18:38:22 -0700456 virtual audio_unique_id_t newAudioUniqueId();
457
Eric Laurentdce54a12014-03-10 12:19:46 -0700458 private:
459 AudioPolicyService *mAudioPolicyService;
460 };
461
Eric Laurentb52c1522014-05-20 11:27:36 -0700462 // --- Notification Client ---
463 class NotificationClient : public IBinder::DeathRecipient {
464 public:
465 NotificationClient(const sp<AudioPolicyService>& service,
466 const sp<IAudioPolicyServiceClient>& client,
467 uid_t uid);
468 virtual ~NotificationClient();
469
470 void onAudioPortListUpdate();
471 void onAudioPatchListUpdate();
472
473 // IBinder::DeathRecipient
474 virtual void binderDied(const wp<IBinder>& who);
475
476 private:
477 NotificationClient(const NotificationClient&);
478 NotificationClient& operator = (const NotificationClient&);
479
480 const wp<AudioPolicyService> mService;
481 const uid_t mUid;
482 const sp<IAudioPolicyServiceClient> mAudioPolicyServiceClient;
483 };
484
Mathias Agopian65ab4712010-07-14 17:59:35 -0700485 // Internal dump utilities.
486 status_t dumpPermissionDenial(int fd);
487
488
Eric Laurenteda6c362011-02-02 09:33:30 -0800489 mutable Mutex mLock; // prevents concurrent access to AudioPolicy manager functions changing
490 // device connection state or routing
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700491 sp<AudioCommandThread> mAudioCommandThread; // audio commands thread
492 sp<AudioCommandThread> mTonePlaybackThread; // tone playback thread
Eric Laurentbfb1b832013-01-07 09:53:42 -0800493 sp<AudioCommandThread> mOutputCommandThread; // process stop and release output
Dima Zavinfce7a472011-04-19 22:30:36 -0700494 struct audio_policy_device *mpAudioPolicyDev;
495 struct audio_policy *mpAudioPolicy;
Eric Laurentf269b8e2014-06-09 20:01:29 -0700496 AudioPolicyInterface *mAudioPolicyManager;
Eric Laurentdce54a12014-03-10 12:19:46 -0700497 AudioPolicyClient *mAudioPolicyClient;
498
Eric Laurentb52c1522014-05-20 11:27:36 -0700499 DefaultKeyedVector< uid_t, sp<NotificationClient> > mNotificationClients;
bryant_liuba2b4392014-06-11 16:49:30 +0800500
501 // Manage all effects configured in audio_effects.conf
502 sp<AudioPolicyEffects> mAudioPolicyEffects;
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700503 audio_mode_t mPhoneState;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700504};
505
506}; // namespace android
507
508#endif // ANDROID_AUDIOPOLICYSERVICE_H