The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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_AUDIO_HARDWARE_INTERFACE_H |
| 18 | #define ANDROID_AUDIO_HARDWARE_INTERFACE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/Errors.h> |
| 24 | #include <utils/Vector.h> |
| 25 | #include <utils/String16.h> |
| 26 | |
| 27 | #include <media/IAudioFlinger.h> |
| 28 | #include "media/AudioSystem.h" |
| 29 | |
| 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | |
| 35 | /** |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 36 | * AudioStreamOut is the abstraction interface for the audio output hardware. |
| 37 | * |
| 38 | * It provides information about various properties of the audio output hardware driver. |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 39 | */ |
| 40 | class AudioStreamOut { |
| 41 | public: |
| 42 | virtual ~AudioStreamOut() = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 43 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 44 | /** return audio sampling rate in hz - eg. 44100 */ |
| 45 | virtual uint32_t sampleRate() const = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 46 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 47 | /** returns size of output buffer - eg. 4800 */ |
| 48 | virtual size_t bufferSize() const = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 49 | |
| 50 | /** |
| 51 | * return number of output audio channels. |
| 52 | * Acceptable values are 1 (mono) or 2 (stereo) |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 53 | */ |
| 54 | virtual int channelCount() const = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 55 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 56 | /** |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 57 | * return audio format in 8bit or 16bit PCM format - |
| 58 | * eg. AudioSystem:PCM_16_BIT |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 59 | */ |
| 60 | virtual int format() const = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 61 | |
| 62 | /** |
| 63 | * return the frame size (number of bytes per sample). |
| 64 | */ |
| 65 | uint32_t frameSize() const { return channelCount()*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } |
| 66 | |
| 67 | /** |
| 68 | * return the audio hardware driver latency in milli seconds. |
| 69 | */ |
| 70 | virtual uint32_t latency() const = 0; |
| 71 | |
| 72 | /** |
| 73 | * Use this method in situations where audio mixing is done in the |
| 74 | * hardware. This method serves as a direct interface with hardware, |
| 75 | * allowing you to directly set the volume as apposed to via the framework. |
| 76 | * This method might produce multiple PCM outputs or hardware accelerated |
| 77 | * codecs, such as MP3 or AAC. |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 78 | */ |
| 79 | virtual status_t setVolume(float volume) = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 80 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 81 | /** write audio buffer to driver. Returns number of bytes written */ |
| 82 | virtual ssize_t write(const void* buffer, size_t bytes) = 0; |
| 83 | |
| 84 | /** dump the state of the audio output device */ |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 85 | virtual status_t dump(int fd, const Vector<String16>& args) = 0; |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /** |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 89 | * AudioStreamIn is the abstraction interface for the audio input hardware. |
| 90 | * |
| 91 | * It defines the various properties of the audio hardware input driver. |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 92 | */ |
| 93 | class AudioStreamIn { |
| 94 | public: |
| 95 | virtual ~AudioStreamIn() = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 96 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 97 | /** return the input buffer size allowed by audio driver */ |
| 98 | virtual size_t bufferSize() const = 0; |
| 99 | |
| 100 | /** return the number of audio input channels */ |
| 101 | virtual int channelCount() const = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 102 | |
| 103 | /** |
| 104 | * return audio format in 8bit or 16bit PCM format - |
| 105 | * eg. AudioSystem:PCM_16_BIT |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 106 | */ |
| 107 | virtual int format() const = 0; |
| 108 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 109 | /** |
| 110 | * return the frame size (number of bytes per sample). |
| 111 | */ |
| 112 | uint32_t frameSize() const { return channelCount()*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } |
| 113 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 114 | /** set the input gain for the audio driver. This method is for |
| 115 | * for future use */ |
| 116 | virtual status_t setGain(float gain) = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 117 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | /** read audio buffer in from audio driver */ |
| 119 | virtual ssize_t read(void* buffer, ssize_t bytes) = 0; |
| 120 | |
| 121 | /** dump the state of the audio input device */ |
| 122 | virtual status_t dump(int fd, const Vector<String16>& args) = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 123 | |
| 124 | /** |
| 125 | * Put the audio hardware input into standby mode. Returns |
| 126 | * status based on include/utils/Errors.h |
| 127 | */ |
| 128 | virtual status_t standby() = 0; |
| 129 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 132 | /** |
| 133 | * AudioHardwareInterface.h defines the interface to the audio hardware abstraction layer. |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | * |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 135 | * The interface supports setting and getting parameters, selecting audio routing |
| 136 | * paths, and defining input and output streams. |
| 137 | * |
| 138 | * AudioFlinger initializes the audio hardware and immediately opens an output stream. |
| 139 | * You can set Audio routing to output to handset, speaker, Bluetooth, or a headset. |
| 140 | * |
| 141 | * The audio input stream is initialized when AudioFlinger is called to carry out |
| 142 | * a record operation. |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 143 | */ |
| 144 | class AudioHardwareInterface |
| 145 | { |
| 146 | public: |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 147 | /** |
| 148 | * check to see if the audio hardware interface has been initialized. |
| 149 | * return status based on values defined in include/utils/Errors.h |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 150 | */ |
| 151 | virtual status_t initCheck() = 0; |
| 152 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 153 | /** |
| 154 | * put the audio hardware into standby mode to conserve power. Returns |
| 155 | * status based on include/utils/Errors.h |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 156 | */ |
| 157 | virtual status_t standby() = 0; |
| 158 | |
| 159 | /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ |
| 160 | virtual status_t setVoiceVolume(float volume) = 0; |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 161 | |
| 162 | /** |
| 163 | * set the audio volume for all audio activities other than voice call. |
| 164 | * Range between 0.0 and 1.0. If any value other than NO_ERROR is returned, |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 165 | * the software mixer will emulate this capability. |
| 166 | */ |
| 167 | virtual status_t setMasterVolume(float volume) = 0; |
| 168 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 169 | /** |
| 170 | * Audio routing methods. Routes defined in include/hardware/AudioSystem.h. |
| 171 | * Audio routes can be (ROUTE_EARPIECE | ROUTE_SPEAKER | ROUTE_BLUETOOTH |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 172 | * | ROUTE_HEADSET) |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 173 | * |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 174 | * setRouting sets the routes for a mode. This is called at startup. It is |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 175 | * also called when a new device is connected, such as a wired headset is |
| 176 | * plugged in or a Bluetooth headset is paired. |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 177 | */ |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 178 | virtual status_t setRouting(int mode, uint32_t routes) = 0; |
| 179 | |
| 180 | virtual status_t getRouting(int mode, uint32_t* routes) = 0; |
| 181 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 182 | /** |
| 183 | * setMode is called when the audio mode changes. NORMAL mode is for |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 184 | * standard audio playback, RINGTONE when a ringtone is playing, and IN_CALL |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 185 | * when a call is in progress. |
| 186 | */ |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 187 | virtual status_t setMode(int mode) = 0; |
| 188 | virtual status_t getMode(int* mode) = 0; |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 189 | |
| 190 | // mic mute |
| 191 | virtual status_t setMicMute(bool state) = 0; |
| 192 | virtual status_t getMicMute(bool* state) = 0; |
| 193 | |
| 194 | // Temporary interface, do not use |
| 195 | // TODO: Replace with a more generic key:value get/set mechanism |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 196 | virtual status_t setParameter(const char* key, const char* value) = 0; |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 197 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 198 | // Returns audio input buffer size according to parameters passed or 0 if one of the |
| 199 | // parameters is not supported |
| 200 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount) = 0; |
| 201 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 202 | /** This method creates and opens the audio hardware output stream */ |
| 203 | virtual AudioStreamOut* openOutputStream( |
| 204 | int format=0, |
| 205 | int channelCount=0, |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 206 | uint32_t sampleRate=0, |
| 207 | status_t *status=0) = 0; |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 208 | |
| 209 | /** This method creates and opens the audio hardware input stream */ |
| 210 | virtual AudioStreamIn* openInputStream( |
| 211 | int format, |
| 212 | int channelCount, |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 213 | uint32_t sampleRate, |
| 214 | status_t *status) = 0; |
| 215 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 216 | /**This method dumps the state of the audio hardware */ |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 217 | virtual status_t dumpState(int fd, const Vector<String16>& args) = 0; |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 218 | |
| 219 | static AudioHardwareInterface* create(); |
| 220 | |
| 221 | protected: |
| 222 | /** |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 223 | * doRouting actually initiates the routing. A call to setRouting |
| 224 | * or setMode may result in a routing change. The generic logic calls |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 225 | * doRouting when required. If the device has any special requirements these |
| 226 | * methods can be overriden. |
| 227 | */ |
| 228 | virtual status_t doRouting() = 0; |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 229 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 230 | virtual status_t dump(int fd, const Vector<String16>& args) = 0; |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | // ---------------------------------------------------------------------------- |
| 234 | |
| 235 | extern "C" AudioHardwareInterface* createAudioHardware(void); |
| 236 | |
| 237 | }; // namespace android |
| 238 | |
| 239 | #endif // ANDROID_AUDIO_HARDWARE_INTERFACE_H |