blob: 08942ee5ee6d3438448e503fa356dabc5e6542fb [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 Laurentdce54a12014-03-10 12:19:46 -070033#include <hardware_legacy/AudioPolicyInterface.h>
bryant_liuba2b4392014-06-11 16:49:30 +080034#include "AudioPolicyEffects.h"
Eric Laurentdce54a12014-03-10 12:19:46 -070035#include "AudioPolicyManager.h"
Dima Zavinfce7a472011-04-19 22:30:36 -070036
bryant_liuba2b4392014-06-11 16:49:30 +080037
Mathias Agopian65ab4712010-07-14 17:59:35 -070038namespace android {
39
Mathias Agopian65ab4712010-07-14 17:59:35 -070040// ----------------------------------------------------------------------------
41
Glenn Kastend2dcb082011-02-03 16:55:26 -080042class AudioPolicyService :
43 public BinderService<AudioPolicyService>,
44 public BnAudioPolicyService,
Eric Laurentde070132010-07-13 04:45:46 -070045 public IBinder::DeathRecipient
Mathias Agopian65ab4712010-07-14 17:59:35 -070046{
Glenn Kastend2dcb082011-02-03 16:55:26 -080047 friend class BinderService<AudioPolicyService>;
Mathias Agopian65ab4712010-07-14 17:59:35 -070048
49public:
Glenn Kastend2dcb082011-02-03 16:55:26 -080050 // for BinderService
Mathias Agopiane762be92013-05-09 16:26:45 -070051 static const char *getServiceName() ANDROID_API { return "media.audio_policy"; }
Mathias Agopian65ab4712010-07-14 17:59:35 -070052
53 virtual status_t dump(int fd, const Vector<String16>& args);
54
55 //
56 // BnAudioPolicyService (see AudioPolicyInterface for method descriptions)
57 //
58
Dima Zavinfce7a472011-04-19 22:30:36 -070059 virtual status_t setDeviceConnectionState(audio_devices_t device,
60 audio_policy_dev_state_t state,
Mathias Agopian65ab4712010-07-14 17:59:35 -070061 const char *device_address);
Dima Zavinfce7a472011-04-19 22:30:36 -070062 virtual audio_policy_dev_state_t getDeviceConnectionState(
63 audio_devices_t device,
Eric Laurentde070132010-07-13 04:45:46 -070064 const char *device_address);
Glenn Kastenf78aee72012-01-04 11:00:47 -080065 virtual status_t setPhoneState(audio_mode_t state);
Dima Zavinfce7a472011-04-19 22:30:36 -070066 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
67 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage);
68 virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
Mathias Agopian65ab4712010-07-14 17:59:35 -070069 uint32_t samplingRate = 0,
Glenn Kasten58f30212012-01-12 12:27:51 -080070 audio_format_t format = AUDIO_FORMAT_DEFAULT,
Glenn Kasten254af182012-07-03 14:59:05 -070071 audio_channel_mask_t channelMask = 0,
Eric Laurent0ca3cf92012-04-18 09:24:29 -070072 audio_output_flags_t flags =
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000073 AUDIO_OUTPUT_FLAG_NONE,
74 const audio_offload_info_t *offloadInfo = NULL);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070075 virtual audio_io_handle_t getOutputForAttr(const audio_attributes_t *attr,
76 uint32_t samplingRate = 0,
77 audio_format_t format = AUDIO_FORMAT_DEFAULT,
78 audio_channel_mask_t channelMask = 0,
79 audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
80 const audio_offload_info_t *offloadInfo = NULL);
Eric Laurentde070132010-07-13 04:45:46 -070081 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -070082 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -070083 int session = 0);
84 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -070085 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -070086 int session = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -070087 virtual void releaseOutput(audio_io_handle_t output);
Glenn Kasteneba51fb2012-01-23 13:58:49 -080088 virtual audio_io_handle_t getInput(audio_source_t inputSource,
Glenn Kastenb3b16602014-07-16 08:36:31 -070089 uint32_t samplingRate,
90 audio_format_t format,
91 audio_channel_mask_t channelMask,
92 int audioSession,
93 audio_input_flags_t flags);
Mathias Agopian65ab4712010-07-14 17:59:35 -070094 virtual status_t startInput(audio_io_handle_t input);
95 virtual status_t stopInput(audio_io_handle_t input);
96 virtual void releaseInput(audio_io_handle_t input);
Dima Zavinfce7a472011-04-19 22:30:36 -070097 virtual status_t initStreamVolume(audio_stream_type_t stream,
Mathias Agopian65ab4712010-07-14 17:59:35 -070098 int indexMin,
99 int indexMax);
Eric Laurent83844cc2011-11-18 16:43:31 -0800100 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
101 int index,
102 audio_devices_t device);
103 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
104 int *index,
105 audio_devices_t device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700106
Dima Zavinfce7a472011-04-19 22:30:36 -0700107 virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
Eric Laurent63742522012-03-08 13:42:42 -0800108 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream);
Eric Laurentde070132010-07-13 04:45:46 -0700109
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700110 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
111 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700112 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700113 uint32_t strategy,
114 int session,
115 int id);
116 virtual status_t unregisterEffect(int id);
Eric Laurentdb7c0792011-08-10 10:37:50 -0700117 virtual status_t setEffectEnabled(int id, bool enabled);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800118 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800119 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700120 virtual bool isSourceActive(audio_source_t source) const;
Eric Laurentde070132010-07-13 04:45:46 -0700121
Eric Laurent57dae992011-07-24 13:36:09 -0700122 virtual status_t queryDefaultPreProcessing(int audioSession,
123 effect_descriptor_t *descriptors,
124 uint32_t *count);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700125 virtual status_t onTransact(
126 uint32_t code,
127 const Parcel& data,
128 Parcel* reply,
129 uint32_t flags);
130
131 // IBinder::DeathRecipient
132 virtual void binderDied(const wp<IBinder>& who);
133
134 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700135 // Helpers for the struct audio_policy_service_ops implementation.
136 // This is used by the audio policy manager for certain operations that
137 // are implemented by the policy service.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700138 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700139 virtual void setParameters(audio_io_handle_t ioHandle,
140 const char *keyValuePairs,
141 int delayMs);
142
143 virtual status_t setStreamVolume(audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700144 float volume,
145 audio_io_handle_t output,
146 int delayMs = 0);
Dima Zavinfce7a472011-04-19 22:30:36 -0700147 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700148 virtual status_t stopTone();
149 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000150 virtual bool isOffloadSupported(const audio_offload_info_t &config);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700151
Eric Laurent203b1a12014-04-01 10:34:16 -0700152 virtual status_t listAudioPorts(audio_port_role_t role,
153 audio_port_type_t type,
154 unsigned int *num_ports,
155 struct audio_port *ports,
156 unsigned int *generation);
157 virtual status_t getAudioPort(struct audio_port *port);
158 virtual status_t createAudioPatch(const struct audio_patch *patch,
159 audio_patch_handle_t *handle);
160 virtual status_t releaseAudioPatch(audio_patch_handle_t handle);
161 virtual status_t listAudioPatches(unsigned int *num_patches,
162 struct audio_patch *patches,
163 unsigned int *generation);
164 virtual status_t setAudioPortConfig(const struct audio_port_config *config);
165
Eric Laurentb52c1522014-05-20 11:27:36 -0700166 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client);
167
Eric Laurentbfb1b832013-01-07 09:53:42 -0800168 status_t doStopOutput(audio_io_handle_t output,
169 audio_stream_type_t stream,
170 int session = 0);
171 void doReleaseOutput(audio_io_handle_t output);
172
Eric Laurent951f4552014-05-20 10:48:17 -0700173 status_t clientCreateAudioPatch(const struct audio_patch *patch,
174 audio_patch_handle_t *handle,
175 int delayMs);
176 status_t clientReleaseAudioPatch(audio_patch_handle_t handle,
177 int delayMs);
Eric Laurente1715a42014-05-20 11:30:42 -0700178 virtual status_t clientSetAudioPortConfig(const struct audio_port_config *config,
179 int delayMs);
180
Eric Laurentb52c1522014-05-20 11:27:36 -0700181 void removeNotificationClient(uid_t uid);
182 void onAudioPortListUpdate();
183 void doOnAudioPortListUpdate();
184 void onAudioPatchListUpdate();
185 void doOnAudioPatchListUpdate();
Eric Laurent951f4552014-05-20 10:48:17 -0700186
Mathias Agopian65ab4712010-07-14 17:59:35 -0700187private:
Mathias Agopiane762be92013-05-09 16:26:45 -0700188 AudioPolicyService() ANDROID_API;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700189 virtual ~AudioPolicyService();
190
191 status_t dumpInternals(int fd);
192
193 // Thread used for tone playback and to send audio config commands to audio flinger
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700194 // For tone playback, using a separate thread is necessary to avoid deadlock with mLock because
195 // startTone() and stopTone() are normally called with mLock locked and requesting a tone start
196 // or stop will cause calls to AudioPolicyService and an attempt to lock mLock.
197 // For audio config commands, it is necessary because audio flinger requires that the calling
198 // process (user) has permission to modify audio settings.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700199 class AudioCommandThread : public Thread {
200 class AudioCommand;
201 public:
202
203 // commands for tone AudioCommand
204 enum {
205 START_TONE,
206 STOP_TONE,
207 SET_VOLUME,
208 SET_PARAMETERS,
Eric Laurentbfb1b832013-01-07 09:53:42 -0800209 SET_VOICE_VOLUME,
210 STOP_OUTPUT,
Eric Laurent951f4552014-05-20 10:48:17 -0700211 RELEASE_OUTPUT,
212 CREATE_AUDIO_PATCH,
213 RELEASE_AUDIO_PATCH,
Eric Laurentb52c1522014-05-20 11:27:36 -0700214 UPDATE_AUDIOPORT_LIST,
Eric Laurente1715a42014-05-20 11:30:42 -0700215 UPDATE_AUDIOPATCH_LIST,
216 SET_AUDIOPORT_CONFIG,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700217 };
218
Eric Laurentbfb1b832013-01-07 09:53:42 -0800219 AudioCommandThread (String8 name, const wp<AudioPolicyService>& service);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700220 virtual ~AudioCommandThread();
221
222 status_t dump(int fd);
223
224 // Thread virtuals
225 virtual void onFirstRef();
226 virtual bool threadLoop();
227
228 void exit();
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800229 void startToneCommand(ToneGenerator::tone_type type,
230 audio_stream_type_t stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700231 void stopToneCommand();
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800232 status_t volumeCommand(audio_stream_type_t stream, float volume,
233 audio_io_handle_t output, int delayMs = 0);
234 status_t parametersCommand(audio_io_handle_t ioHandle,
235 const char *keyValuePairs, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700236 status_t voiceVolumeCommand(float volume, int delayMs = 0);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800237 void stopOutputCommand(audio_io_handle_t output,
238 audio_stream_type_t stream,
239 int session);
240 void releaseOutputCommand(audio_io_handle_t output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700241 status_t sendCommand(sp<AudioCommand>& command, int delayMs = 0);
242 void insertCommand_l(sp<AudioCommand>& command, int delayMs = 0);
Eric Laurent951f4552014-05-20 10:48:17 -0700243 status_t createAudioPatchCommand(const struct audio_patch *patch,
244 audio_patch_handle_t *handle,
245 int delayMs);
246 status_t releaseAudioPatchCommand(audio_patch_handle_t handle,
247 int delayMs);
Eric Laurentb52c1522014-05-20 11:27:36 -0700248 void updateAudioPortListCommand();
249 void updateAudioPatchListCommand();
Eric Laurente1715a42014-05-20 11:30:42 -0700250 status_t setAudioPortConfigCommand(const struct audio_port_config *config,
251 int delayMs);
Eric Laurent951f4552014-05-20 10:48:17 -0700252 void insertCommand_l(AudioCommand *command, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700253
254 private:
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100255 class AudioCommandData;
256
Mathias Agopian65ab4712010-07-14 17:59:35 -0700257 // descriptor for requested tone playback event
Eric Laurent0ede8922014-05-09 18:04:42 -0700258 class AudioCommand: public RefBase {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700259
260 public:
261 AudioCommand()
Eric Laurent0ede8922014-05-09 18:04:42 -0700262 : mCommand(-1), mStatus(NO_ERROR), mWaitStatus(false) {}
Mathias Agopian65ab4712010-07-14 17:59:35 -0700263
264 void dump(char* buffer, size_t size);
265
266 int mCommand; // START_TONE, STOP_TONE ...
267 nsecs_t mTime; // time stamp
Eric Laurent0ede8922014-05-09 18:04:42 -0700268 Mutex mLock; // mutex associated to mCond
Mathias Agopian65ab4712010-07-14 17:59:35 -0700269 Condition mCond; // condition for status return
270 status_t mStatus; // command status
271 bool mWaitStatus; // true if caller is waiting for status
Eric Laurent0ede8922014-05-09 18:04:42 -0700272 sp<AudioCommandData> mParam; // command specific parameter data
Mathias Agopian65ab4712010-07-14 17:59:35 -0700273 };
274
Eric Laurent0ede8922014-05-09 18:04:42 -0700275 class AudioCommandData: public RefBase {
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100276 public:
277 virtual ~AudioCommandData() {}
278 protected:
279 AudioCommandData() {}
280 };
281
282 class ToneData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700283 public:
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800284 ToneGenerator::tone_type mType; // tone type (START_TONE only)
Glenn Kastenfff6d712012-01-12 16:38:12 -0800285 audio_stream_type_t mStream; // stream type (START_TONE only)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700286 };
287
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100288 class VolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700289 public:
Glenn Kastenfff6d712012-01-12 16:38:12 -0800290 audio_stream_type_t mStream;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700291 float mVolume;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800292 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700293 };
294
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100295 class ParametersData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700296 public:
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800297 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700298 String8 mKeyValuePairs;
299 };
300
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100301 class VoiceVolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700302 public:
303 float mVolume;
304 };
305
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100306 class StopOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800307 public:
308 audio_io_handle_t mIO;
309 audio_stream_type_t mStream;
310 int mSession;
311 };
312
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100313 class ReleaseOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800314 public:
315 audio_io_handle_t mIO;
316 };
317
Eric Laurent951f4552014-05-20 10:48:17 -0700318 class CreateAudioPatchData : public AudioCommandData {
319 public:
320 struct audio_patch mPatch;
321 audio_patch_handle_t mHandle;
322 };
323
324 class ReleaseAudioPatchData : public AudioCommandData {
325 public:
326 audio_patch_handle_t mHandle;
327 };
328
Eric Laurente1715a42014-05-20 11:30:42 -0700329 class SetAudioPortConfigData : public AudioCommandData {
330 public:
331 struct audio_port_config mConfig;
332 };
333
Mathias Agopian65ab4712010-07-14 17:59:35 -0700334 Mutex mLock;
335 Condition mWaitWorkCV;
Eric Laurent0ede8922014-05-09 18:04:42 -0700336 Vector < sp<AudioCommand> > mAudioCommands; // list of pending commands
Mathias Agopian65ab4712010-07-14 17:59:35 -0700337 ToneGenerator *mpToneGenerator; // the tone generator
Eric Laurent0ede8922014-05-09 18:04:42 -0700338 sp<AudioCommand> mLastCommand; // last processed command (used by dump)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700339 String8 mName; // string used by wake lock fo delayed commands
Eric Laurentbfb1b832013-01-07 09:53:42 -0800340 wp<AudioPolicyService> mService;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700341 };
342
Eric Laurentdce54a12014-03-10 12:19:46 -0700343 class AudioPolicyClient : public AudioPolicyClientInterface
344 {
345 public:
346 AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {}
347 virtual ~AudioPolicyClient() {}
348
349 //
350 // Audio HW module functions
351 //
352
353 // loads a HW module.
354 virtual audio_module_handle_t loadHwModule(const char *name);
355
356 //
357 // Audio output Control functions
358 //
359
360 // opens an audio output with the requested parameters. The parameter values can indicate to use the default values
361 // in case the audio policy manager has no specific requirements for the output being opened.
362 // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream.
363 // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly.
364 virtual audio_io_handle_t openOutput(audio_module_handle_t module,
365 audio_devices_t *pDevices,
366 uint32_t *pSamplingRate,
367 audio_format_t *pFormat,
368 audio_channel_mask_t *pChannelMask,
369 uint32_t *pLatencyMs,
370 audio_output_flags_t flags,
371 const audio_offload_info_t *offloadInfo = NULL);
372 // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by
373 // a special mixer thread in the AudioFlinger.
374 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2);
375 // closes the output stream
376 virtual status_t closeOutput(audio_io_handle_t output);
377 // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in
378 // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded.
379 virtual status_t suspendOutput(audio_io_handle_t output);
380 // restores a suspended output.
381 virtual status_t restoreOutput(audio_io_handle_t output);
382
383 //
384 // Audio input Control functions
385 //
386
387 // opens an audio input
388 virtual audio_io_handle_t openInput(audio_module_handle_t module,
389 audio_devices_t *pDevices,
390 uint32_t *pSamplingRate,
391 audio_format_t *pFormat,
Glenn Kastenec40d282014-07-15 15:31:26 -0700392 audio_channel_mask_t *pChannelMask,
393 audio_input_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700394 // closes an audio input
395 virtual status_t closeInput(audio_io_handle_t input);
396 //
397 // misc control functions
398 //
399
400 // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes
401 // for each output (destination device) it is attached to.
402 virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0);
403
404 // invalidate a stream type, causing a reroute to an unspecified new output
405 virtual status_t invalidateStream(audio_stream_type_t stream);
406
407 // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface.
408 virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0);
409 // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager.
410 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
411
412 // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing
413 // over a telephony device during a phone call.
414 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
415 virtual status_t stopTone();
416
417 // set down link audio volume.
418 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
419
420 // move effect to the specified output
421 virtual status_t moveEffects(int session,
422 audio_io_handle_t srcOutput,
423 audio_io_handle_t dstOutput);
424
Eric Laurent951f4552014-05-20 10:48:17 -0700425 /* Create a patch between several source and sink ports */
426 virtual status_t createAudioPatch(const struct audio_patch *patch,
427 audio_patch_handle_t *handle,
428 int delayMs);
429
430 /* Release a patch */
431 virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
432 int delayMs);
433
Eric Laurente1715a42014-05-20 11:30:42 -0700434 /* Set audio port configuration */
435 virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs);
436
Eric Laurentb52c1522014-05-20 11:27:36 -0700437 virtual void onAudioPortListUpdate();
438 virtual void onAudioPatchListUpdate();
439
Eric Laurentdce54a12014-03-10 12:19:46 -0700440 private:
441 AudioPolicyService *mAudioPolicyService;
442 };
443
Eric Laurentb52c1522014-05-20 11:27:36 -0700444 // --- Notification Client ---
445 class NotificationClient : public IBinder::DeathRecipient {
446 public:
447 NotificationClient(const sp<AudioPolicyService>& service,
448 const sp<IAudioPolicyServiceClient>& client,
449 uid_t uid);
450 virtual ~NotificationClient();
451
452 void onAudioPortListUpdate();
453 void onAudioPatchListUpdate();
454
455 // IBinder::DeathRecipient
456 virtual void binderDied(const wp<IBinder>& who);
457
458 private:
459 NotificationClient(const NotificationClient&);
460 NotificationClient& operator = (const NotificationClient&);
461
462 const wp<AudioPolicyService> mService;
463 const uid_t mUid;
464 const sp<IAudioPolicyServiceClient> mAudioPolicyServiceClient;
465 };
466
Mathias Agopian65ab4712010-07-14 17:59:35 -0700467 // Internal dump utilities.
468 status_t dumpPermissionDenial(int fd);
469
470
Eric Laurenteda6c362011-02-02 09:33:30 -0800471 mutable Mutex mLock; // prevents concurrent access to AudioPolicy manager functions changing
472 // device connection state or routing
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700473 sp<AudioCommandThread> mAudioCommandThread; // audio commands thread
474 sp<AudioCommandThread> mTonePlaybackThread; // tone playback thread
Eric Laurentbfb1b832013-01-07 09:53:42 -0800475 sp<AudioCommandThread> mOutputCommandThread; // process stop and release output
Dima Zavinfce7a472011-04-19 22:30:36 -0700476 struct audio_policy_device *mpAudioPolicyDev;
477 struct audio_policy *mpAudioPolicy;
Eric Laurentf269b8e2014-06-09 20:01:29 -0700478 AudioPolicyInterface *mAudioPolicyManager;
Eric Laurentdce54a12014-03-10 12:19:46 -0700479 AudioPolicyClient *mAudioPolicyClient;
480
Eric Laurentb52c1522014-05-20 11:27:36 -0700481 DefaultKeyedVector< uid_t, sp<NotificationClient> > mNotificationClients;
bryant_liuba2b4392014-06-11 16:49:30 +0800482
483 // Manage all effects configured in audio_effects.conf
484 sp<AudioPolicyEffects> mAudioPolicyEffects;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700485};
486
487}; // namespace android
488
489#endif // ANDROID_AUDIOPOLICYSERVICE_H