Home | History | Annotate | Download | only in media
      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 #include <utils/RefBase.h>
     24 #include <utils/Errors.h>
     25 #include <binder/IInterface.h>
     26 #include <media/AudioSystem.h>
     27 #include <media/AudioPolicy.h>
     28 #include <media/IAudioPolicyServiceClient.h>
     29 #include <system/audio_policy.h>
     30 #include <vector>
     31 
     32 namespace android {
     33 
     34 // ----------------------------------------------------------------------------
     35 
     36 class IAudioPolicyService : public IInterface
     37 {
     38 public:
     39     DECLARE_META_INTERFACE(AudioPolicyService);
     40 
     41     //
     42     // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
     43     //
     44     virtual status_t setDeviceConnectionState(audio_devices_t device,
     45                                               audio_policy_dev_state_t state,
     46                                               const char *device_address,
     47                                               const char *device_name,
     48                                               audio_format_t encodedFormat) = 0;
     49     virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
     50                                                                   const char *device_address) = 0;
     51     virtual status_t handleDeviceConfigChange(audio_devices_t device,
     52                                               const char *device_address,
     53                                               const char *device_name,
     54                                               audio_format_t encodedFormat) = 0;
     55     virtual status_t setPhoneState(audio_mode_t state) = 0;
     56     virtual status_t setForceUse(audio_policy_force_use_t usage,
     57                                     audio_policy_forced_cfg_t config) = 0;
     58     virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) = 0;
     59     virtual audio_io_handle_t getOutput(audio_stream_type_t stream) = 0;
     60     virtual status_t getOutputForAttr(audio_attributes_t *attr,
     61                                       audio_io_handle_t *output,
     62                                       audio_session_t session,
     63                                       audio_stream_type_t *stream,
     64                                       pid_t pid,
     65                                       uid_t uid,
     66                                       const audio_config_t *config,
     67                                       audio_output_flags_t flags,
     68                                       audio_port_handle_t *selectedDeviceId,
     69                                       audio_port_handle_t *portId,
     70                                       std::vector<audio_io_handle_t> *secondaryOutputs) = 0;
     71     virtual status_t startOutput(audio_port_handle_t portId) = 0;
     72     virtual status_t stopOutput(audio_port_handle_t portId) = 0;
     73     virtual void releaseOutput(audio_port_handle_t portId) = 0;
     74     virtual status_t  getInputForAttr(const audio_attributes_t *attr,
     75                               audio_io_handle_t *input,
     76                               audio_unique_id_t riid,
     77                               audio_session_t session,
     78                               pid_t pid,
     79                               uid_t uid,
     80                               const String16& opPackageName,
     81                               const audio_config_base_t *config,
     82                               audio_input_flags_t flags,
     83                               audio_port_handle_t *selectedDeviceId,
     84                               audio_port_handle_t *portId) = 0;
     85     virtual status_t startInput(audio_port_handle_t portId) = 0;
     86     virtual status_t stopInput(audio_port_handle_t portId) = 0;
     87     virtual void releaseInput(audio_port_handle_t portId) = 0;
     88     virtual status_t initStreamVolume(audio_stream_type_t stream,
     89                                       int indexMin,
     90                                       int indexMax) = 0;
     91     virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
     92                                           int index,
     93                                           audio_devices_t device) = 0;
     94     virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
     95                                           int *index,
     96                                           audio_devices_t device) = 0;
     97 
     98     virtual status_t setVolumeIndexForAttributes(const audio_attributes_t &attr,
     99                                                  int index,
    100                                                  audio_devices_t device) = 0;
    101     virtual status_t getVolumeIndexForAttributes(const audio_attributes_t &attr,
    102                                                  int &index,
    103                                                  audio_devices_t device) = 0;
    104     virtual status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index) = 0;
    105 
    106     virtual status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index) = 0;
    107 
    108     virtual uint32_t getStrategyForStream(audio_stream_type_t stream) = 0;
    109     virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0;
    110     virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0;
    111     virtual status_t registerEffect(const effect_descriptor_t *desc,
    112                                     audio_io_handle_t io,
    113                                     uint32_t strategy,
    114                                     audio_session_t session,
    115                                     int id) = 0;
    116     virtual status_t unregisterEffect(int id) = 0;
    117     virtual status_t setEffectEnabled(int id, bool enabled) = 0;
    118     virtual status_t moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) = 0;
    119     virtual bool     isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const = 0;
    120     virtual bool     isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0)
    121                              const = 0;
    122     virtual bool     isSourceActive(audio_source_t source) const = 0;
    123     virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
    124                                               effect_descriptor_t *descriptors,
    125                                               uint32_t *count) = 0;
    126     virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
    127                                             const String16& opPackageName,
    128                                             const effect_uuid_t *uuid,
    129                                             int32_t priority,
    130                                             audio_source_t source,
    131                                             audio_unique_id_t* id) = 0;
    132     virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
    133                                             const String16& opPackageName,
    134                                             const effect_uuid_t *uuid,
    135                                             int32_t priority,
    136                                             audio_usage_t usage,
    137                                             audio_unique_id_t* id) = 0;
    138     virtual status_t removeSourceDefaultEffect(audio_unique_id_t id) = 0;
    139     virtual status_t removeStreamDefaultEffect(audio_unique_id_t id) = 0;
    140     virtual status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) = 0;
    141    // Check if offload is possible for given format, stream type, sample rate,
    142     // bit rate, duration, video and streaming or offload property is enabled
    143     virtual bool isOffloadSupported(const audio_offload_info_t& info) = 0;
    144 
    145     // Check if direct playback is possible for given format, sample rate, channel mask and flags.
    146     virtual bool isDirectOutputSupported(const audio_config_base_t& config,
    147                                          const audio_attributes_t& attributes) = 0;
    148 
    149     /* List available audio ports and their attributes */
    150     virtual status_t listAudioPorts(audio_port_role_t role,
    151                                     audio_port_type_t type,
    152                                     unsigned int *num_ports,
    153                                     struct audio_port *ports,
    154                                     unsigned int *generation) = 0;
    155 
    156     /* Get attributes for a given audio port */
    157     virtual status_t getAudioPort(struct audio_port *port) = 0;
    158 
    159     /* Create an audio patch between several source and sink ports */
    160     virtual status_t createAudioPatch(const struct audio_patch *patch,
    161                                        audio_patch_handle_t *handle) = 0;
    162 
    163     /* Release an audio patch */
    164     virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0;
    165 
    166     /* List existing audio patches */
    167     virtual status_t listAudioPatches(unsigned int *num_patches,
    168                                       struct audio_patch *patches,
    169                                       unsigned int *generation) = 0;
    170     /* Set audio port configuration */
    171     virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
    172 
    173     virtual void registerClient(const sp<IAudioPolicyServiceClient>& client) = 0;
    174 
    175     virtual void setAudioPortCallbacksEnabled(bool enabled) = 0;
    176 
    177     virtual void setAudioVolumeGroupCallbacksEnabled(bool enabled) = 0;
    178 
    179     virtual status_t acquireSoundTriggerSession(audio_session_t *session,
    180                                            audio_io_handle_t *ioHandle,
    181                                            audio_devices_t *device) = 0;
    182 
    183     virtual status_t releaseSoundTriggerSession(audio_session_t session) = 0;
    184 
    185     virtual audio_mode_t getPhoneState() = 0;
    186 
    187     virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) = 0;
    188 
    189     virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
    190             = 0;
    191 
    192     virtual status_t removeUidDeviceAffinities(uid_t uid) = 0;
    193 
    194     virtual status_t startAudioSource(const struct audio_port_config *source,
    195                                       const audio_attributes_t *attributes,
    196                                       audio_port_handle_t *portId) = 0;
    197     virtual status_t stopAudioSource(audio_port_handle_t portId) = 0;
    198 
    199     virtual status_t setMasterMono(bool mono) = 0;
    200     virtual status_t getMasterMono(bool *mono) = 0;
    201     virtual float    getStreamVolumeDB(
    202             audio_stream_type_t stream, int index, audio_devices_t device) = 0;
    203 
    204     virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
    205                                         audio_format_t *surroundFormats,
    206                                         bool *surroundFormatsEnabled,
    207                                         bool reported) = 0;
    208     virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
    209                                         std::vector<audio_format_t> *formats) = 0;
    210     virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) = 0;
    211 
    212     virtual status_t setAssistantUid(uid_t uid) = 0;
    213     virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids) = 0;
    214 
    215     virtual bool     isHapticPlaybackSupported() = 0;
    216     virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies) = 0;
    217     virtual status_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa,
    218                                                            product_strategy_t &productStrategy) = 0;
    219 
    220     virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups) = 0;
    221     virtual status_t getVolumeGroupFromAudioAttributes(const AudioAttributes &aa,
    222                                                        volume_group_t &volumeGroup) = 0;
    223 
    224     virtual status_t setRttEnabled(bool enabled) = 0;
    225 };
    226 
    227 
    228 // ----------------------------------------------------------------------------
    229 
    230 class BnAudioPolicyService : public BnInterface<IAudioPolicyService>
    231 {
    232 public:
    233     virtual status_t    onTransact( uint32_t code,
    234                                     const Parcel& data,
    235                                     Parcel* reply,
    236                                     uint32_t flags = 0);
    237 private:
    238     void sanetizeAudioAttributes(audio_attributes_t* attr);
    239     status_t sanitizeEffectDescriptor(effect_descriptor_t* desc);
    240     status_t sanitizeAudioPortConfig(struct audio_port_config* config);
    241 };
    242 
    243 // ----------------------------------------------------------------------------
    244 
    245 }; // namespace android
    246 
    247 #endif // ANDROID_IAUDIOPOLICYSERVICE_H
    248