00001 /* 00002 * Copyright (C) 2007 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef ANDROID_AUDIO_HARDWARE_INTERFACE_H 00018 #define ANDROID_AUDIO_HARDWARE_INTERFACE_H 00019 00020 #include <stdint.h> 00021 #include <sys/types.h> 00022 00023 #include <utils/Errors.h> 00024 #include <utils/Vector.h> 00025 #include <utils/String16.h> 00026 00027 #include <media/IAudioFlinger.h> 00028 #include "media/AudioSystem.h" 00029 00030 00031 namespace android { 00032 00033 // ---------------------------------------------------------------------------- 00034 00035 /** 00036 * AudioStreamOut is the abstraction interface for the audio output hardware. 00037 * 00038 * It provides information about various properties of the audio output hardware driver. 00039 */ 00040 class AudioStreamOut { 00041 public: 00042 virtual ~AudioStreamOut() = 0; 00043 00044 /** return audio sampling rate in hz - eg. 44100 */ 00045 virtual uint32_t sampleRate() const = 0; 00046 00047 /** returns size of output buffer - eg. 4800 */ 00048 virtual size_t bufferSize() const = 0; 00049 00050 /** 00051 * return number of output audio channels. 00052 * Acceptable values are 1 (mono) or 2 (stereo) 00053 */ 00054 virtual int channelCount() const = 0; 00055 00056 /** 00057 * return audio format in 8bit or 16bit PCM format - 00058 * eg. AudioSystem:PCM_16_BIT 00059 */ 00060 virtual int format() const = 0; 00061 00062 /** 00063 * return the frame size (number of bytes per sample). 00064 */ 00065 uint32_t frameSize() const { return channelCount()*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } 00066 00067 /** 00068 * return the audio hardware driver latency in milli seconds. 00069 */ 00070 virtual uint32_t latency() const = 0; 00071 00072 /** 00073 * Use this method in situations where audio mixing is done in the 00074 * hardware. This method serves as a direct interface with hardware, 00075 * allowing you to directly set the volume as apposed to via the framework. 00076 * This method might produce multiple PCM outputs or hardware accelerated 00077 * codecs, such as MP3 or AAC. 00078 */ 00079 virtual status_t setVolume(float volume) = 0; 00080 00081 /** write audio buffer to driver. Returns number of bytes written */ 00082 virtual ssize_t write(const void* buffer, size_t bytes) = 0; 00083 00084 /** dump the state of the audio output device */ 00085 virtual status_t dump(int fd, const Vector<String16>& args) = 0; 00086 }; 00087 00088 /** 00089 * AudioStreamIn is the abstraction interface for the audio input hardware. 00090 * 00091 * It defines the various properties of the audio hardware input driver. 00092 */ 00093 class AudioStreamIn { 00094 public: 00095 virtual ~AudioStreamIn() = 0; 00096 00097 /** return the input buffer size allowed by audio driver */ 00098 virtual size_t bufferSize() const = 0; 00099 00100 /** return the number of audio input channels */ 00101 virtual int channelCount() const = 0; 00102 00103 /** 00104 * return audio format in 8bit or 16bit PCM format - 00105 * eg. AudioSystem:PCM_16_BIT 00106 */ 00107 virtual int format() const = 0; 00108 00109 /** 00110 * return the frame size (number of bytes per sample). 00111 */ 00112 uint32_t frameSize() const { return channelCount()*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } 00113 00114 /** set the input gain for the audio driver. This method is for 00115 * for future use */ 00116 virtual status_t setGain(float gain) = 0; 00117 00118 /** read audio buffer in from audio driver */ 00119 virtual ssize_t read(void* buffer, ssize_t bytes) = 0; 00120 00121 /** dump the state of the audio input device */ 00122 virtual status_t dump(int fd, const Vector<String16>& args) = 0; 00123 00124 /** 00125 * Put the audio hardware input into standby mode. Returns 00126 * status based on include/utils/Errors.h 00127 */ 00128 virtual status_t standby() = 0; 00129 00130 }; 00131 00132 /** 00133 * AudioHardwareInterface.h defines the interface to the audio hardware abstraction layer. 00134 * 00135 * The interface supports setting and getting parameters, selecting audio routing 00136 * paths, and defining input and output streams. 00137 * 00138 * AudioFlinger initializes the audio hardware and immediately opens an output stream. 00139 * You can set Audio routing to output to handset, speaker, Bluetooth, or a headset. 00140 * 00141 * The audio input stream is initialized when AudioFlinger is called to carry out 00142 * a record operation. 00143 */ 00144 class AudioHardwareInterface 00145 { 00146 public: 00147 /** 00148 * check to see if the audio hardware interface has been initialized. 00149 * return status based on values defined in include/utils/Errors.h 00150 */ 00151 virtual status_t initCheck() = 0; 00152 00153 /** 00154 * put the audio hardware into standby mode to conserve power. Returns 00155 * status based on include/utils/Errors.h 00156 */ 00157 virtual status_t standby() = 0; 00158 00159 /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ 00160 virtual status_t setVoiceVolume(float volume) = 0; 00161 00162 /** 00163 * set the audio volume for all audio activities other than voice call. 00164 * Range between 0.0 and 1.0. If any value other than NO_ERROR is returned, 00165 * the software mixer will emulate this capability. 00166 */ 00167 virtual status_t setMasterVolume(float volume) = 0; 00168 00169 /** 00170 * Audio routing methods. Routes defined in include/hardware/AudioSystem.h. 00171 * Audio routes can be (ROUTE_EARPIECE | ROUTE_SPEAKER | ROUTE_BLUETOOTH 00172 * | ROUTE_HEADSET) 00173 * 00174 * setRouting sets the routes for a mode. This is called at startup. It is 00175 * also called when a new device is connected, such as a wired headset is 00176 * plugged in or a Bluetooth headset is paired. 00177 */ 00178 virtual status_t setRouting(int mode, uint32_t routes) = 0; 00179 00180 virtual status_t getRouting(int mode, uint32_t* routes) = 0; 00181 00182 /** 00183 * setMode is called when the audio mode changes. NORMAL mode is for 00184 * standard audio playback, RINGTONE when a ringtone is playing, and IN_CALL 00185 * when a call is in progress. 00186 */ 00187 virtual status_t setMode(int mode) = 0; 00188 virtual status_t getMode(int* mode) = 0; 00189 00190 // mic mute 00191 virtual status_t setMicMute(bool state) = 0; 00192 virtual status_t getMicMute(bool* state) = 0; 00193 00194 // Temporary interface, do not use 00195 // TODO: Replace with a more generic key:value get/set mechanism 00196 virtual status_t setParameter(const char* key, const char* value) = 0; 00197 00198 // Returns audio input buffer size according to parameters passed or 0 if one of the 00199 // parameters is not supported 00200 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount) = 0; 00201 00202 /** This method creates and opens the audio hardware output stream */ 00203 virtual AudioStreamOut* openOutputStream( 00204 int format=0, 00205 int channelCount=0, 00206 uint32_t sampleRate=0, 00207 status_t *status=0) = 0; 00208 00209 /** This method creates and opens the audio hardware input stream */ 00210 virtual AudioStreamIn* openInputStream( 00211 int format, 00212 int channelCount, 00213 uint32_t sampleRate, 00214 status_t *status) = 0; 00215 00216 /**This method dumps the state of the audio hardware */ 00217 virtual status_t dumpState(int fd, const Vector<String16>& args) = 0; 00218 00219 static AudioHardwareInterface* create(); 00220 00221 protected: 00222 /** 00223 * doRouting actually initiates the routing. A call to setRouting 00224 * or setMode may result in a routing change. The generic logic calls 00225 * doRouting when required. If the device has any special requirements these 00226 * methods can be overriden. 00227 */ 00228 virtual status_t doRouting() = 0; 00229 00230 virtual status_t dump(int fd, const Vector<String16>& args) = 0; 00231 }; 00232 00233 // ---------------------------------------------------------------------------- 00234 00235 extern "C" AudioHardwareInterface* createAudioHardware(void); 00236 00237 }; // namespace android 00238 00239 #endif // ANDROID_AUDIO_HARDWARE_INTERFACE_H