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 
     24 #include <utils/RefBase.h>
     25 #include <utils/Errors.h>
     26 #include <binder/IInterface.h>
     27 #include <media/AudioSystem.h>
     28 #include <media/IAudioPolicyServiceClient.h>
     29 
     30 #include <system/audio_policy.h>
     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) = 0;
     47     virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
     48                                                                   const char *device_address) = 0;
     49     virtual status_t setPhoneState(audio_mode_t state) = 0;
     50     virtual status_t setForceUse(audio_policy_force_use_t usage,
     51                                     audio_policy_forced_cfg_t config) = 0;
     52     virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) = 0;
     53     virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
     54                                         uint32_t samplingRate = 0,
     55                                         audio_format_t format = AUDIO_FORMAT_DEFAULT,
     56                                         audio_channel_mask_t channelMask = 0,
     57                                         audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
     58                                         const audio_offload_info_t *offloadInfo = NULL) = 0;
     59     virtual audio_io_handle_t getOutputForAttr(const audio_attributes_t *attr,
     60                                             uint32_t samplingRate = 0,
     61                                             audio_format_t format = AUDIO_FORMAT_DEFAULT,
     62                                             audio_channel_mask_t channelMask = 0,
     63                                             audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
     64                                             const audio_offload_info_t *offloadInfo = NULL) = 0;
     65     virtual status_t startOutput(audio_io_handle_t output,
     66                                  audio_stream_type_t stream,
     67                                  int session = 0) = 0;
     68     virtual status_t stopOutput(audio_io_handle_t output,
     69                                 audio_stream_type_t stream,
     70                                 int session = 0) = 0;
     71     virtual void releaseOutput(audio_io_handle_t output) = 0;
     72     virtual audio_io_handle_t getInput(audio_source_t inputSource,
     73                                     uint32_t samplingRate,
     74                                     audio_format_t format,
     75                                     audio_channel_mask_t channelMask,
     76                                     int audioSession,
     77                                     audio_input_flags_t flags) = 0;
     78     virtual status_t startInput(audio_io_handle_t input,
     79                                 audio_session_t session) = 0;
     80     virtual status_t stopInput(audio_io_handle_t input,
     81                                audio_session_t session) = 0;
     82     virtual void releaseInput(audio_io_handle_t input,
     83                               audio_session_t session) = 0;
     84     virtual status_t initStreamVolume(audio_stream_type_t stream,
     85                                       int indexMin,
     86                                       int indexMax) = 0;
     87     virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
     88                                           int index,
     89                                           audio_devices_t device) = 0;
     90     virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
     91                                           int *index,
     92                                           audio_devices_t device) = 0;
     93     virtual uint32_t getStrategyForStream(audio_stream_type_t stream) = 0;
     94     virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0;
     95     virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0;
     96     virtual status_t registerEffect(const effect_descriptor_t *desc,
     97                                     audio_io_handle_t io,
     98                                     uint32_t strategy,
     99                                     int session,
    100                                     int id) = 0;
    101     virtual status_t unregisterEffect(int id) = 0;
    102     virtual status_t setEffectEnabled(int id, bool enabled) = 0;
    103     virtual bool     isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const = 0;
    104     virtual bool     isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0)
    105                              const = 0;
    106     virtual bool     isSourceActive(audio_source_t source) const = 0;
    107     virtual status_t queryDefaultPreProcessing(int audioSession,
    108                                               effect_descriptor_t *descriptors,
    109                                               uint32_t *count) = 0;
    110    // Check if offload is possible for given format, stream type, sample rate,
    111     // bit rate, duration, video and streaming or offload property is enabled
    112     virtual bool isOffloadSupported(const audio_offload_info_t& info) = 0;
    113 
    114     /* List available audio ports and their attributes */
    115     virtual status_t listAudioPorts(audio_port_role_t role,
    116                                     audio_port_type_t type,
    117                                     unsigned int *num_ports,
    118                                     struct audio_port *ports,
    119                                     unsigned int *generation) = 0;
    120 
    121     /* Get attributes for a given audio port */
    122     virtual status_t getAudioPort(struct audio_port *port) = 0;
    123 
    124     /* Create an audio patch between several source and sink ports */
    125     virtual status_t createAudioPatch(const struct audio_patch *patch,
    126                                        audio_patch_handle_t *handle) = 0;
    127 
    128     /* Release an audio patch */
    129     virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0;
    130 
    131     /* List existing audio patches */
    132     virtual status_t listAudioPatches(unsigned int *num_patches,
    133                                       struct audio_patch *patches,
    134                                       unsigned int *generation) = 0;
    135     /* Set audio port configuration */
    136     virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
    137 
    138     virtual void registerClient(const sp<IAudioPolicyServiceClient>& client) = 0;
    139 
    140     virtual status_t acquireSoundTriggerSession(audio_session_t *session,
    141                                            audio_io_handle_t *ioHandle,
    142                                            audio_devices_t *device) = 0;
    143 
    144     virtual status_t releaseSoundTriggerSession(audio_session_t session) = 0;
    145 
    146     virtual audio_mode_t getPhoneState() = 0;
    147 };
    148 
    149 
    150 // ----------------------------------------------------------------------------
    151 
    152 class BnAudioPolicyService : public BnInterface<IAudioPolicyService>
    153 {
    154 public:
    155     virtual status_t    onTransact( uint32_t code,
    156                                     const Parcel& data,
    157                                     Parcel* reply,
    158                                     uint32_t flags = 0);
    159 };
    160 
    161 // ----------------------------------------------------------------------------
    162 
    163 }; // namespace android
    164 
    165 #endif // ANDROID_IAUDIOPOLICYSERVICE_H
    166