1/* //device/servers/AudioFlinger/AudioHardwareStub.cpp 2** 3** Copyright 2007, The Android Open Source Project 4** 5** Licensed under the Apache License, Version 2.0 (the "License"); 6** you may not use this file except in compliance with the License. 7** You may obtain a copy of the License at 8** 9** http://www.apache.org/licenses/LICENSE-2.0 10** 11** Unless required by applicable law or agreed to in writing, software 12** distributed under the License is distributed on an "AS IS" BASIS, 13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14** See the License for the specific language governing permissions and 15** limitations under the License. 16*/ 17 18#include <stdint.h> 19#include <sys/types.h> 20 21#include <stdlib.h> 22#include <unistd.h> 23#include <utils/String8.h> 24 25#include "AudioHardwareStub.h" 26#include <media/AudioRecord.h> 27 28namespace android { 29 30// ---------------------------------------------------------------------------- 31 32AudioHardwareStub::AudioHardwareStub() : mMicMute(false) 33{ 34} 35 36AudioHardwareStub::~AudioHardwareStub() 37{ 38} 39 40status_t AudioHardwareStub::initCheck() 41{ 42 return NO_ERROR; 43} 44 45AudioStreamOut* AudioHardwareStub::openOutputStream( 46 uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) 47{ 48 AudioStreamOutStub* out = new AudioStreamOutStub(); 49 status_t lStatus = out->set(format, channels, sampleRate); 50 if (status) { 51 *status = lStatus; 52 } 53 if (lStatus == NO_ERROR) 54 return out; 55 delete out; 56 return 0; 57} 58 59void AudioHardwareStub::closeOutputStream(AudioStreamOut* out) 60{ 61 delete out; 62} 63 64AudioStreamIn* AudioHardwareStub::openInputStream( 65 uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, 66 status_t *status, AudioSystem::audio_in_acoustics acoustics) 67{ 68 // check for valid input source 69 if (!AudioSystem::isInputDevice((AudioSystem::audio_devices)devices)) { 70 return 0; 71 } 72 73 AudioStreamInStub* in = new AudioStreamInStub(); 74 status_t lStatus = in->set(format, channels, sampleRate, acoustics); 75 if (status) { 76 *status = lStatus; 77 } 78 if (lStatus == NO_ERROR) 79 return in; 80 delete in; 81 return 0; 82} 83 84void AudioHardwareStub::closeInputStream(AudioStreamIn* in) 85{ 86 delete in; 87} 88 89status_t AudioHardwareStub::setVoiceVolume(float volume) 90{ 91 return NO_ERROR; 92} 93 94status_t AudioHardwareStub::setMasterVolume(float volume) 95{ 96 return NO_ERROR; 97} 98 99status_t AudioHardwareStub::dumpInternals(int fd, const Vector<String16>& args) 100{ 101 const size_t SIZE = 256; 102 char buffer[SIZE]; 103 String8 result; 104 result.append("AudioHardwareStub::dumpInternals\n"); 105 snprintf(buffer, SIZE, "\tmMicMute: %s\n", mMicMute? "true": "false"); 106 result.append(buffer); 107 ::write(fd, result.string(), result.size()); 108 return NO_ERROR; 109} 110 111status_t AudioHardwareStub::dump(int fd, const Vector<String16>& args) 112{ 113 dumpInternals(fd, args); 114 return NO_ERROR; 115} 116 117// ---------------------------------------------------------------------------- 118 119status_t AudioStreamOutStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate) 120{ 121 if (pFormat) *pFormat = format(); 122 if (pChannels) *pChannels = channels(); 123 if (pRate) *pRate = sampleRate(); 124 125 return NO_ERROR; 126} 127 128ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes) 129{ 130 // fake timing for audio output 131 usleep(bytes * 1000000 / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate()); 132 return bytes; 133} 134 135status_t AudioStreamOutStub::standby() 136{ 137 return NO_ERROR; 138} 139 140status_t AudioStreamOutStub::dump(int fd, const Vector<String16>& args) 141{ 142 const size_t SIZE = 256; 143 char buffer[SIZE]; 144 String8 result; 145 snprintf(buffer, SIZE, "AudioStreamOutStub::dump\n"); 146 snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); 147 snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); 148 snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); 149 snprintf(buffer, SIZE, "\tformat: %d\n", format()); 150 result.append(buffer); 151 ::write(fd, result.string(), result.size()); 152 return NO_ERROR; 153} 154 155String8 AudioStreamOutStub::getParameters(const String8& keys) 156{ 157 AudioParameter param = AudioParameter(keys); 158 return param.toString(); 159} 160 161status_t AudioStreamOutStub::getRenderPosition(uint32_t *dspFrames) 162{ 163 return INVALID_OPERATION; 164} 165 166// ---------------------------------------------------------------------------- 167 168status_t AudioStreamInStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate, 169 AudioSystem::audio_in_acoustics acoustics) 170{ 171 return NO_ERROR; 172} 173 174ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes) 175{ 176 // fake timing for audio input 177 usleep(bytes * 1000000 / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate()); 178 memset(buffer, 0, bytes); 179 return bytes; 180} 181 182status_t AudioStreamInStub::dump(int fd, const Vector<String16>& args) 183{ 184 const size_t SIZE = 256; 185 char buffer[SIZE]; 186 String8 result; 187 snprintf(buffer, SIZE, "AudioStreamInStub::dump\n"); 188 result.append(buffer); 189 snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); 190 result.append(buffer); 191 snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); 192 result.append(buffer); 193 snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); 194 result.append(buffer); 195 snprintf(buffer, SIZE, "\tformat: %d\n", format()); 196 result.append(buffer); 197 ::write(fd, result.string(), result.size()); 198 return NO_ERROR; 199} 200 201String8 AudioStreamInStub::getParameters(const String8& keys) 202{ 203 AudioParameter param = AudioParameter(keys); 204 return param.toString(); 205} 206 207// ---------------------------------------------------------------------------- 208 209}; // namespace android 210