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