Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2007 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_IAUDIOFLINGER_H
     18 #define ANDROID_IAUDIOFLINGER_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/IAudioTrack.h>
     28 #include <media/IAudioRecord.h>
     29 #include <media/IAudioFlingerClient.h>
     30 #include <system/audio.h>
     31 #include <system/audio_policy.h>
     32 #include <hardware/audio_policy.h>
     33 #include <hardware/audio_effect.h>
     34 #include <media/IEffect.h>
     35 #include <media/IEffectClient.h>
     36 #include <utils/String8.h>
     37 
     38 namespace android {
     39 
     40 // ----------------------------------------------------------------------------
     41 
     42 class IAudioFlinger : public IInterface
     43 {
     44 public:
     45     DECLARE_META_INTERFACE(AudioFlinger);
     46 
     47     // or-able bits shared by createTrack and openRecord, but not all combinations make sense
     48     enum {
     49         TRACK_DEFAULT = 0,  // client requests a default AudioTrack
     50         TRACK_TIMED   = 1,  // client requests a TimedAudioTrack
     51         TRACK_FAST    = 2,  // client requests a fast AudioTrack
     52     };
     53     typedef uint32_t track_flags_t;
     54 
     55     /* create an audio track and registers it with AudioFlinger.
     56      * return null if the track cannot be created.
     57      */
     58     virtual sp<IAudioTrack> createTrack(
     59                                 pid_t pid,
     60                                 audio_stream_type_t streamType,
     61                                 uint32_t sampleRate,
     62                                 audio_format_t format,
     63                                 uint32_t channelMask,
     64                                 int frameCount,
     65                                 track_flags_t flags,
     66                                 const sp<IMemory>& sharedBuffer,
     67                                 audio_io_handle_t output,
     68                                 pid_t tid,  // -1 means unused, otherwise must be valid non-0
     69                                 int *sessionId,
     70                                 status_t *status) = 0;
     71 
     72     virtual sp<IAudioRecord> openRecord(
     73                                 pid_t pid,
     74                                 audio_io_handle_t input,
     75                                 uint32_t sampleRate,
     76                                 audio_format_t format,
     77                                 uint32_t channelMask,
     78                                 int frameCount,
     79                                 track_flags_t flags,
     80                                 int *sessionId,
     81                                 status_t *status) = 0;
     82 
     83     /* query the audio hardware state. This state never changes,
     84      * and therefore can be cached.
     85      */
     86     virtual     uint32_t    sampleRate(audio_io_handle_t output) const = 0;
     87     virtual     int         channelCount(audio_io_handle_t output) const = 0;
     88     virtual     audio_format_t format(audio_io_handle_t output) const = 0;
     89     virtual     size_t      frameCount(audio_io_handle_t output) const = 0;
     90 
     91     // return estimated latency in milliseconds
     92     virtual     uint32_t    latency(audio_io_handle_t output) const = 0;
     93 
     94     /* set/get the audio hardware state. This will probably be used by
     95      * the preference panel, mostly.
     96      */
     97     virtual     status_t    setMasterVolume(float value) = 0;
     98     virtual     status_t    setMasterMute(bool muted) = 0;
     99 
    100     virtual     float       masterVolume() const = 0;
    101     virtual     bool        masterMute() const = 0;
    102 
    103     /* set/get stream type state. This will probably be used by
    104      * the preference panel, mostly.
    105      */
    106     virtual     status_t    setStreamVolume(audio_stream_type_t stream, float value,
    107                                     audio_io_handle_t output) = 0;
    108     virtual     status_t    setStreamMute(audio_stream_type_t stream, bool muted) = 0;
    109 
    110     virtual     float       streamVolume(audio_stream_type_t stream,
    111                                     audio_io_handle_t output) const = 0;
    112     virtual     bool        streamMute(audio_stream_type_t stream) const = 0;
    113 
    114     // set audio mode
    115     virtual     status_t    setMode(audio_mode_t mode) = 0;
    116 
    117     // mic mute/state
    118     virtual     status_t    setMicMute(bool state) = 0;
    119     virtual     bool        getMicMute() const = 0;
    120 
    121     virtual     status_t    setParameters(audio_io_handle_t ioHandle,
    122                                     const String8& keyValuePairs) = 0;
    123     virtual     String8     getParameters(audio_io_handle_t ioHandle, const String8& keys) const = 0;
    124 
    125     // register a current process for audio output change notifications
    126     virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
    127 
    128     // retrieve the audio recording buffer size
    129     virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount) const = 0;
    130 
    131     virtual audio_io_handle_t openOutput(audio_module_handle_t module,
    132                                          audio_devices_t *pDevices,
    133                                          uint32_t *pSamplingRate,
    134                                          audio_format_t *pFormat,
    135                                          audio_channel_mask_t *pChannelMask,
    136                                          uint32_t *pLatencyMs,
    137                                          audio_output_flags_t flags) = 0;
    138     virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
    139                                     audio_io_handle_t output2) = 0;
    140     virtual status_t closeOutput(audio_io_handle_t output) = 0;
    141     virtual status_t suspendOutput(audio_io_handle_t output) = 0;
    142     virtual status_t restoreOutput(audio_io_handle_t output) = 0;
    143 
    144     virtual audio_io_handle_t openInput(audio_module_handle_t module,
    145                                         audio_devices_t *pDevices,
    146                                         uint32_t *pSamplingRate,
    147                                         audio_format_t *pFormat,
    148                                         audio_channel_mask_t *pChannelMask) = 0;
    149     virtual status_t closeInput(audio_io_handle_t input) = 0;
    150 
    151     virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0;
    152 
    153     virtual status_t setVoiceVolume(float volume) = 0;
    154 
    155     virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
    156                                     audio_io_handle_t output) const = 0;
    157 
    158     virtual unsigned int getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
    159 
    160     virtual int newAudioSessionId() = 0;
    161 
    162     virtual void acquireAudioSessionId(int audioSession) = 0;
    163     virtual void releaseAudioSessionId(int audioSession) = 0;
    164 
    165     virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
    166 
    167     virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
    168 
    169     virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
    170                                         effect_descriptor_t *pDescriptor) const = 0;
    171 
    172     virtual sp<IEffect> createEffect(pid_t pid,
    173                                     effect_descriptor_t *pDesc,
    174                                     const sp<IEffectClient>& client,
    175                                     int32_t priority,
    176                                     audio_io_handle_t output,
    177                                     int sessionId,
    178                                     status_t *status,
    179                                     int *id,
    180                                     int *enabled) = 0;
    181 
    182     virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
    183                                     audio_io_handle_t dstOutput) = 0;
    184 
    185     virtual audio_module_handle_t loadHwModule(const char *name) = 0;
    186 };
    187 
    188 
    189 // ----------------------------------------------------------------------------
    190 
    191 class BnAudioFlinger : public BnInterface<IAudioFlinger>
    192 {
    193 public:
    194     virtual status_t    onTransact( uint32_t code,
    195                                     const Parcel& data,
    196                                     Parcel* reply,
    197                                     uint32_t flags = 0);
    198 };
    199 
    200 // ----------------------------------------------------------------------------
    201 
    202 }; // namespace android
    203 
    204 #endif // ANDROID_IAUDIOFLINGER_H
    205