blob: 97236e343f1ab4c7b5405bbee0facf61c702008a [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);
Eric Laurent4dc68062014-07-28 17:26:49 -070094 virtual status_t startInput(audio_io_handle_t input,
95 audio_session_t session);
96 virtual status_t stopInput(audio_io_handle_t input,
97 audio_session_t session);
98 virtual void releaseInput(audio_io_handle_t input,
99 audio_session_t session);
Dima Zavinfce7a472011-04-19 22:30:36 -0700100 virtual status_t initStreamVolume(audio_stream_type_t stream,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700101 int indexMin,
102 int indexMax);
Eric Laurent83844cc2011-11-18 16:43:31 -0800103 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
104 int index,
105 audio_devices_t device);
106 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
107 int *index,
108 audio_devices_t device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700109
Dima Zavinfce7a472011-04-19 22:30:36 -0700110 virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
Eric Laurent63742522012-03-08 13:42:42 -0800111 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream);
Eric Laurentde070132010-07-13 04:45:46 -0700112
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700113 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
114 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700115 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700116 uint32_t strategy,
117 int session,
118 int id);
119 virtual status_t unregisterEffect(int id);
Eric Laurentdb7c0792011-08-10 10:37:50 -0700120 virtual status_t setEffectEnabled(int id, bool enabled);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800121 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800122 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700123 virtual bool isSourceActive(audio_source_t source) const;
Eric Laurentde070132010-07-13 04:45:46 -0700124
Eric Laurent57dae992011-07-24 13:36:09 -0700125 virtual status_t queryDefaultPreProcessing(int audioSession,
126 effect_descriptor_t *descriptors,
127 uint32_t *count);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700128 virtual status_t onTransact(
129 uint32_t code,
130 const Parcel& data,
131 Parcel* reply,
132 uint32_t flags);
133
134 // IBinder::DeathRecipient
135 virtual void binderDied(const wp<IBinder>& who);
136
137 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700138 // Helpers for the struct audio_policy_service_ops implementation.
139 // This is used by the audio policy manager for certain operations that
140 // are implemented by the policy service.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700141 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700142 virtual void setParameters(audio_io_handle_t ioHandle,
143 const char *keyValuePairs,
144 int delayMs);
145
146 virtual status_t setStreamVolume(audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700147 float volume,
148 audio_io_handle_t output,
149 int delayMs = 0);
Dima Zavinfce7a472011-04-19 22:30:36 -0700150 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700151 virtual status_t stopTone();
152 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000153 virtual bool isOffloadSupported(const audio_offload_info_t &config);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700154
Eric Laurent203b1a12014-04-01 10:34:16 -0700155 virtual status_t listAudioPorts(audio_port_role_t role,
156 audio_port_type_t type,
157 unsigned int *num_ports,
158 struct audio_port *ports,
159 unsigned int *generation);
160 virtual status_t getAudioPort(struct audio_port *port);
161 virtual status_t createAudioPatch(const struct audio_patch *patch,
162 audio_patch_handle_t *handle);
163 virtual status_t releaseAudioPatch(audio_patch_handle_t handle);
164 virtual status_t listAudioPatches(unsigned int *num_patches,
165 struct audio_patch *patches,
166 unsigned int *generation);
167 virtual status_t setAudioPortConfig(const struct audio_port_config *config);
168
Eric Laurentb52c1522014-05-20 11:27:36 -0700169 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client);
170
Eric Laurentbfb1b832013-01-07 09:53:42 -0800171 status_t doStopOutput(audio_io_handle_t output,
172 audio_stream_type_t stream,
173 int session = 0);
174 void doReleaseOutput(audio_io_handle_t output);
175
Eric Laurent951f4552014-05-20 10:48:17 -0700176 status_t clientCreateAudioPatch(const struct audio_patch *patch,
177 audio_patch_handle_t *handle,
178 int delayMs);
179 status_t clientReleaseAudioPatch(audio_patch_handle_t handle,
180 int delayMs);
Eric Laurente1715a42014-05-20 11:30:42 -0700181 virtual status_t clientSetAudioPortConfig(const struct audio_port_config *config,
182 int delayMs);
183
Eric Laurentb52c1522014-05-20 11:27:36 -0700184 void removeNotificationClient(uid_t uid);
185 void onAudioPortListUpdate();
186 void doOnAudioPortListUpdate();
187 void onAudioPatchListUpdate();
188 void doOnAudioPatchListUpdate();
Eric Laurent951f4552014-05-20 10:48:17 -0700189
Mathias Agopian65ab4712010-07-14 17:59:35 -0700190private:
Mathias Agopiane762be92013-05-09 16:26:45 -0700191 AudioPolicyService() ANDROID_API;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700192 virtual ~AudioPolicyService();
193
194 status_t dumpInternals(int fd);
195
196 // Thread used for tone playback and to send audio config commands to audio flinger
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700197 // For tone playback, using a separate thread is necessary to avoid deadlock with mLock because
198 // startTone() and stopTone() are normally called with mLock locked and requesting a tone start
199 // or stop will cause calls to AudioPolicyService and an attempt to lock mLock.
200 // For audio config commands, it is necessary because audio flinger requires that the calling
201 // process (user) has permission to modify audio settings.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700202 class AudioCommandThread : public Thread {
203 class AudioCommand;
204 public:
205
206 // commands for tone AudioCommand
207 enum {
208 START_TONE,
209 STOP_TONE,
210 SET_VOLUME,
211 SET_PARAMETERS,
Eric Laurentbfb1b832013-01-07 09:53:42 -0800212 SET_VOICE_VOLUME,
213 STOP_OUTPUT,
Eric Laurent951f4552014-05-20 10:48:17 -0700214 RELEASE_OUTPUT,
215 CREATE_AUDIO_PATCH,
216 RELEASE_AUDIO_PATCH,
Eric Laurentb52c1522014-05-20 11:27:36 -0700217 UPDATE_AUDIOPORT_LIST,
Eric Laurente1715a42014-05-20 11:30:42 -0700218 UPDATE_AUDIOPATCH_LIST,
219 SET_AUDIOPORT_CONFIG,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700220 };
221
Eric Laurentbfb1b832013-01-07 09:53:42 -0800222 AudioCommandThread (String8 name, const wp<AudioPolicyService>& service);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700223 virtual ~AudioCommandThread();
224
225 status_t dump(int fd);
226
227 // Thread virtuals
228 virtual void onFirstRef();
229 virtual bool threadLoop();
230
231 void exit();
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800232 void startToneCommand(ToneGenerator::tone_type type,
233 audio_stream_type_t stream);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700234 void stopToneCommand();
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800235 status_t volumeCommand(audio_stream_type_t stream, float volume,
236 audio_io_handle_t output, int delayMs = 0);
237 status_t parametersCommand(audio_io_handle_t ioHandle,
238 const char *keyValuePairs, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700239 status_t voiceVolumeCommand(float volume, int delayMs = 0);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800240 void stopOutputCommand(audio_io_handle_t output,
241 audio_stream_type_t stream,
242 int session);
243 void releaseOutputCommand(audio_io_handle_t output);
Eric Laurent0ede8922014-05-09 18:04:42 -0700244 status_t sendCommand(sp<AudioCommand>& command, int delayMs = 0);
245 void insertCommand_l(sp<AudioCommand>& command, int delayMs = 0);
Eric Laurent951f4552014-05-20 10:48:17 -0700246 status_t createAudioPatchCommand(const struct audio_patch *patch,
247 audio_patch_handle_t *handle,
248 int delayMs);
249 status_t releaseAudioPatchCommand(audio_patch_handle_t handle,
250 int delayMs);
Eric Laurentb52c1522014-05-20 11:27:36 -0700251 void updateAudioPortListCommand();
252 void updateAudioPatchListCommand();
Eric Laurente1715a42014-05-20 11:30:42 -0700253 status_t setAudioPortConfigCommand(const struct audio_port_config *config,
254 int delayMs);
Eric Laurent951f4552014-05-20 10:48:17 -0700255 void insertCommand_l(AudioCommand *command, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700256
257 private:
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100258 class AudioCommandData;
259
Mathias Agopian65ab4712010-07-14 17:59:35 -0700260 // descriptor for requested tone playback event
Eric Laurent0ede8922014-05-09 18:04:42 -0700261 class AudioCommand: public RefBase {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700262
263 public:
264 AudioCommand()
Eric Laurent0ede8922014-05-09 18:04:42 -0700265 : mCommand(-1), mStatus(NO_ERROR), mWaitStatus(false) {}
Mathias Agopian65ab4712010-07-14 17:59:35 -0700266
267 void dump(char* buffer, size_t size);
268
269 int mCommand; // START_TONE, STOP_TONE ...
270 nsecs_t mTime; // time stamp
Eric Laurent0ede8922014-05-09 18:04:42 -0700271 Mutex mLock; // mutex associated to mCond
Mathias Agopian65ab4712010-07-14 17:59:35 -0700272 Condition mCond; // condition for status return
273 status_t mStatus; // command status
274 bool mWaitStatus; // true if caller is waiting for status
Eric Laurent0ede8922014-05-09 18:04:42 -0700275 sp<AudioCommandData> mParam; // command specific parameter data
Mathias Agopian65ab4712010-07-14 17:59:35 -0700276 };
277
Eric Laurent0ede8922014-05-09 18:04:42 -0700278 class AudioCommandData: public RefBase {
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100279 public:
280 virtual ~AudioCommandData() {}
281 protected:
282 AudioCommandData() {}
283 };
284
285 class ToneData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700286 public:
Glenn Kasten3d2f8772012-01-27 15:25:25 -0800287 ToneGenerator::tone_type mType; // tone type (START_TONE only)
Glenn Kastenfff6d712012-01-12 16:38:12 -0800288 audio_stream_type_t mStream; // stream type (START_TONE only)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700289 };
290
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100291 class VolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700292 public:
Glenn Kastenfff6d712012-01-12 16:38:12 -0800293 audio_stream_type_t mStream;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700294 float mVolume;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800295 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700296 };
297
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100298 class ParametersData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700299 public:
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800300 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700301 String8 mKeyValuePairs;
302 };
303
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100304 class VoiceVolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700305 public:
306 float mVolume;
307 };
308
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100309 class StopOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800310 public:
311 audio_io_handle_t mIO;
312 audio_stream_type_t mStream;
313 int mSession;
314 };
315
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100316 class ReleaseOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800317 public:
318 audio_io_handle_t mIO;
319 };
320
Eric Laurent951f4552014-05-20 10:48:17 -0700321 class CreateAudioPatchData : public AudioCommandData {
322 public:
323 struct audio_patch mPatch;
324 audio_patch_handle_t mHandle;
325 };
326
327 class ReleaseAudioPatchData : public AudioCommandData {
328 public:
329 audio_patch_handle_t mHandle;
330 };
331
Eric Laurente1715a42014-05-20 11:30:42 -0700332 class SetAudioPortConfigData : public AudioCommandData {
333 public:
334 struct audio_port_config mConfig;
335 };
336
Mathias Agopian65ab4712010-07-14 17:59:35 -0700337 Mutex mLock;
338 Condition mWaitWorkCV;
Eric Laurent0ede8922014-05-09 18:04:42 -0700339 Vector < sp<AudioCommand> > mAudioCommands; // list of pending commands
Mathias Agopian65ab4712010-07-14 17:59:35 -0700340 ToneGenerator *mpToneGenerator; // the tone generator
Eric Laurent0ede8922014-05-09 18:04:42 -0700341 sp<AudioCommand> mLastCommand; // last processed command (used by dump)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700342 String8 mName; // string used by wake lock fo delayed commands
Eric Laurentbfb1b832013-01-07 09:53:42 -0800343 wp<AudioPolicyService> mService;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700344 };
345
Eric Laurentdce54a12014-03-10 12:19:46 -0700346 class AudioPolicyClient : public AudioPolicyClientInterface
347 {
348 public:
349 AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {}
350 virtual ~AudioPolicyClient() {}
351
352 //
353 // Audio HW module functions
354 //
355
356 // loads a HW module.
357 virtual audio_module_handle_t loadHwModule(const char *name);
358
359 //
360 // Audio output Control functions
361 //
362
363 // opens an audio output with the requested parameters. The parameter values can indicate to use the default values
364 // in case the audio policy manager has no specific requirements for the output being opened.
365 // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream.
366 // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly.
Eric Laurentcf2c0212014-07-25 16:20:43 -0700367 virtual status_t openOutput(audio_module_handle_t module,
368 audio_io_handle_t *output,
369 audio_config_t *config,
370 audio_devices_t *devices,
371 const String8& address,
372 uint32_t *latencyMs,
373 audio_output_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700374 // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by
375 // a special mixer thread in the AudioFlinger.
376 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2);
377 // closes the output stream
378 virtual status_t closeOutput(audio_io_handle_t output);
379 // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in
380 // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded.
381 virtual status_t suspendOutput(audio_io_handle_t output);
382 // restores a suspended output.
383 virtual status_t restoreOutput(audio_io_handle_t output);
384
385 //
386 // Audio input Control functions
387 //
388
389 // opens an audio input
390 virtual audio_io_handle_t openInput(audio_module_handle_t module,
Eric Laurentcf2c0212014-07-25 16:20:43 -0700391 audio_io_handle_t *input,
392 audio_config_t *config,
393 audio_devices_t *devices,
394 const String8& address,
395 audio_source_t source,
Glenn Kastenec40d282014-07-15 15:31:26 -0700396 audio_input_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700397 // closes an audio input
398 virtual status_t closeInput(audio_io_handle_t input);
399 //
400 // misc control functions
401 //
402
403 // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes
404 // for each output (destination device) it is attached to.
405 virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0);
406
407 // invalidate a stream type, causing a reroute to an unspecified new output
408 virtual status_t invalidateStream(audio_stream_type_t stream);
409
410 // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface.
411 virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0);
412 // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager.
413 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
414
415 // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing
416 // over a telephony device during a phone call.
417 virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
418 virtual status_t stopTone();
419
420 // set down link audio volume.
421 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
422
423 // move effect to the specified output
424 virtual status_t moveEffects(int session,
425 audio_io_handle_t srcOutput,
426 audio_io_handle_t dstOutput);
427
Eric Laurent951f4552014-05-20 10:48:17 -0700428 /* Create a patch between several source and sink ports */
429 virtual status_t createAudioPatch(const struct audio_patch *patch,
430 audio_patch_handle_t *handle,
431 int delayMs);
432
433 /* Release a patch */
434 virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
435 int delayMs);
436
Eric Laurente1715a42014-05-20 11:30:42 -0700437 /* Set audio port configuration */
438 virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs);
439
Eric Laurentb52c1522014-05-20 11:27:36 -0700440 virtual void onAudioPortListUpdate();
441 virtual void onAudioPatchListUpdate();
442
Eric Laurentde3f8392014-07-27 18:38:22 -0700443 virtual audio_unique_id_t newAudioUniqueId();
444
Eric Laurentdce54a12014-03-10 12:19:46 -0700445 private:
446 AudioPolicyService *mAudioPolicyService;
447 };
448
Eric Laurentb52c1522014-05-20 11:27:36 -0700449 // --- Notification Client ---
450 class NotificationClient : public IBinder::DeathRecipient {
451 public:
452 NotificationClient(const sp<AudioPolicyService>& service,
453 const sp<IAudioPolicyServiceClient>& client,
454 uid_t uid);
455 virtual ~NotificationClient();
456
457 void onAudioPortListUpdate();
458 void onAudioPatchListUpdate();
459
460 // IBinder::DeathRecipient
461 virtual void binderDied(const wp<IBinder>& who);
462
463 private:
464 NotificationClient(const NotificationClient&);
465 NotificationClient& operator = (const NotificationClient&);
466
467 const wp<AudioPolicyService> mService;
468 const uid_t mUid;
469 const sp<IAudioPolicyServiceClient> mAudioPolicyServiceClient;
470 };
471
Mathias Agopian65ab4712010-07-14 17:59:35 -0700472 // Internal dump utilities.
473 status_t dumpPermissionDenial(int fd);
474
475
Eric Laurenteda6c362011-02-02 09:33:30 -0800476 mutable Mutex mLock; // prevents concurrent access to AudioPolicy manager functions changing
477 // device connection state or routing
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700478 sp<AudioCommandThread> mAudioCommandThread; // audio commands thread
479 sp<AudioCommandThread> mTonePlaybackThread; // tone playback thread
Eric Laurentbfb1b832013-01-07 09:53:42 -0800480 sp<AudioCommandThread> mOutputCommandThread; // process stop and release output
Dima Zavinfce7a472011-04-19 22:30:36 -0700481 struct audio_policy_device *mpAudioPolicyDev;
482 struct audio_policy *mpAudioPolicy;
Eric Laurentf269b8e2014-06-09 20:01:29 -0700483 AudioPolicyInterface *mAudioPolicyManager;
Eric Laurentdce54a12014-03-10 12:19:46 -0700484 AudioPolicyClient *mAudioPolicyClient;
485
Eric Laurentb52c1522014-05-20 11:27:36 -0700486 DefaultKeyedVector< uid_t, sp<NotificationClient> > mNotificationClients;
bryant_liuba2b4392014-06-11 16:49:30 +0800487
488 // Manage all effects configured in audio_effects.conf
489 sp<AudioPolicyEffects> mAudioPolicyEffects;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700490};
491
492}; // namespace android
493
494#endif // ANDROID_AUDIOPOLICYSERVICE_H