• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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_IAUDIOPOLICYSERVICE_H
18 #define ANDROID_IAUDIOPOLICYSERVICE_H
19 
20 #include <stdint.h>
21 #include <sys/types.h>
22 #include <unistd.h>
23 
24 #include <utils/RefBase.h>
25 #include <utils/Errors.h>
26 #include <binder/IInterface.h>
27 #include <media/AudioSystem.h>
28 #include <media/AudioPolicy.h>
29 #include <media/IAudioPolicyServiceClient.h>
30 
31 #include <system/audio_policy.h>
32 
33 namespace android {
34 
35 // ----------------------------------------------------------------------------
36 
37 class IAudioPolicyService : public IInterface
38 {
39 public:
40     DECLARE_META_INTERFACE(AudioPolicyService);
41 
42     //
43     // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
44     //
45     virtual status_t setDeviceConnectionState(audio_devices_t device,
46                                               audio_policy_dev_state_t state,
47                                               const char *device_address,
48                                               const char *device_name) = 0;
49     virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
50                                                                   const char *device_address) = 0;
51     virtual status_t setPhoneState(audio_mode_t state) = 0;
52     virtual status_t setForceUse(audio_policy_force_use_t usage,
53                                     audio_policy_forced_cfg_t config) = 0;
54     virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) = 0;
55     virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
56                                         uint32_t samplingRate = 0,
57                                         audio_format_t format = AUDIO_FORMAT_DEFAULT,
58                                         audio_channel_mask_t channelMask = 0,
59                                         audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
60                                         const audio_offload_info_t *offloadInfo = NULL) = 0;
61     virtual status_t getOutputForAttr(const audio_attributes_t *attr,
62                                       audio_io_handle_t *output,
63                                       audio_session_t session,
64                                       audio_stream_type_t *stream,
65                                       uid_t uid,
66                                       uint32_t samplingRate = 0,
67                                       audio_format_t format = AUDIO_FORMAT_DEFAULT,
68                                       audio_channel_mask_t channelMask = 0,
69                                       audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
70                                       audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE,
71                                       const audio_offload_info_t *offloadInfo = NULL) = 0;
72     virtual status_t startOutput(audio_io_handle_t output,
73                                  audio_stream_type_t stream,
74                                  audio_session_t session) = 0;
75     virtual status_t stopOutput(audio_io_handle_t output,
76                                 audio_stream_type_t stream,
77                                 audio_session_t session) = 0;
78     virtual void releaseOutput(audio_io_handle_t output,
79                                audio_stream_type_t stream,
80                                audio_session_t session) = 0;
81     virtual status_t  getInputForAttr(const audio_attributes_t *attr,
82                               audio_io_handle_t *input,
83                               audio_session_t session,
84                               pid_t pid,
85                               uid_t uid,
86                               uint32_t samplingRate,
87                               audio_format_t format,
88                               audio_channel_mask_t channelMask,
89                               audio_input_flags_t flags,
90                               audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE) = 0;
91     virtual status_t startInput(audio_io_handle_t input,
92                                 audio_session_t session) = 0;
93     virtual status_t stopInput(audio_io_handle_t input,
94                                audio_session_t session) = 0;
95     virtual void releaseInput(audio_io_handle_t input,
96                               audio_session_t session) = 0;
97     virtual status_t initStreamVolume(audio_stream_type_t stream,
98                                       int indexMin,
99                                       int indexMax) = 0;
100     virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
101                                           int index,
102                                           audio_devices_t device) = 0;
103     virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
104                                           int *index,
105                                           audio_devices_t device) = 0;
106     virtual uint32_t getStrategyForStream(audio_stream_type_t stream) = 0;
107     virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0;
108     virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0;
109     virtual status_t registerEffect(const effect_descriptor_t *desc,
110                                     audio_io_handle_t io,
111                                     uint32_t strategy,
112                                     audio_session_t session,
113                                     int id) = 0;
114     virtual status_t unregisterEffect(int id) = 0;
115     virtual status_t setEffectEnabled(int id, bool enabled) = 0;
116     virtual bool     isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const = 0;
117     virtual bool     isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0)
118                              const = 0;
119     virtual bool     isSourceActive(audio_source_t source) const = 0;
120     virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
121                                               effect_descriptor_t *descriptors,
122                                               uint32_t *count) = 0;
123    // Check if offload is possible for given format, stream type, sample rate,
124     // bit rate, duration, video and streaming or offload property is enabled
125     virtual bool isOffloadSupported(const audio_offload_info_t& info) = 0;
126 
127     /* List available audio ports and their attributes */
128     virtual status_t listAudioPorts(audio_port_role_t role,
129                                     audio_port_type_t type,
130                                     unsigned int *num_ports,
131                                     struct audio_port *ports,
132                                     unsigned int *generation) = 0;
133 
134     /* Get attributes for a given audio port */
135     virtual status_t getAudioPort(struct audio_port *port) = 0;
136 
137     /* Create an audio patch between several source and sink ports */
138     virtual status_t createAudioPatch(const struct audio_patch *patch,
139                                        audio_patch_handle_t *handle) = 0;
140 
141     /* Release an audio patch */
142     virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0;
143 
144     /* List existing audio patches */
145     virtual status_t listAudioPatches(unsigned int *num_patches,
146                                       struct audio_patch *patches,
147                                       unsigned int *generation) = 0;
148     /* Set audio port configuration */
149     virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
150 
151     virtual void registerClient(const sp<IAudioPolicyServiceClient>& client) = 0;
152 
153     virtual void setAudioPortCallbacksEnabled(bool enabled) = 0;
154 
155     virtual status_t acquireSoundTriggerSession(audio_session_t *session,
156                                            audio_io_handle_t *ioHandle,
157                                            audio_devices_t *device) = 0;
158 
159     virtual status_t releaseSoundTriggerSession(audio_session_t session) = 0;
160 
161     virtual audio_mode_t getPhoneState() = 0;
162 
163     virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration) = 0;
164 
165     virtual status_t startAudioSource(const struct audio_port_config *source,
166                                       const audio_attributes_t *attributes,
167                                       audio_io_handle_t *handle) = 0;
168     virtual status_t stopAudioSource(audio_io_handle_t handle) = 0;
169 
170     virtual status_t setMasterMono(bool mono) = 0;
171     virtual status_t getMasterMono(bool *mono) = 0;
172 };
173 
174 
175 // ----------------------------------------------------------------------------
176 
177 class BnAudioPolicyService : public BnInterface<IAudioPolicyService>
178 {
179 public:
180     virtual status_t    onTransact( uint32_t code,
181                                     const Parcel& data,
182                                     Parcel* reply,
183                                     uint32_t flags = 0);
184 };
185 
186 // ----------------------------------------------------------------------------
187 
188 }; // namespace android
189 
190 #endif // ANDROID_IAUDIOPOLICYSERVICE_H
191