The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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" |
Dave Sparks | a5a11d4 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 26 | #include <media/AudioRecord.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | // ---------------------------------------------------------------------------- |
| 31 | |
| 32 | AudioHardwareStub::AudioHardwareStub() : mMicMute(false) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | AudioHardwareStub::~AudioHardwareStub() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | status_t AudioHardwareStub::initCheck() |
| 41 | { |
| 42 | return NO_ERROR; |
| 43 | } |
| 44 | |
| 45 | AudioStreamOut* AudioHardwareStub::openOutputStream( |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 46 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | { |
| 48 | AudioStreamOutStub* out = new AudioStreamOutStub(); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 49 | status_t lStatus = out->set(format, channels, sampleRate); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | if (status) { |
| 51 | *status = lStatus; |
| 52 | } |
| 53 | if (lStatus == NO_ERROR) |
| 54 | return out; |
| 55 | delete out; |
| 56 | return 0; |
| 57 | } |
| 58 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 59 | void AudioHardwareStub::closeOutputStream(AudioStreamOut* out) |
| 60 | { |
| 61 | delete out; |
| 62 | } |
| 63 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | AudioStreamIn* AudioHardwareStub::openInputStream( |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 65 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | status_t *status, AudioSystem::audio_in_acoustics acoustics) |
| 67 | { |
Dave Sparks | a5a11d4 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 68 | // check for valid input source |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 69 | if (!AudioSystem::isInputDevice((AudioSystem::audio_devices)devices)) { |
Dave Sparks | a5a11d4 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | AudioStreamInStub* in = new AudioStreamInStub(); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 74 | status_t lStatus = in->set(format, channels, sampleRate, acoustics); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | if (status) { |
| 76 | *status = lStatus; |
| 77 | } |
| 78 | if (lStatus == NO_ERROR) |
| 79 | return in; |
| 80 | delete in; |
| 81 | return 0; |
| 82 | } |
| 83 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 84 | void AudioHardwareStub::closeInputStream(AudioStreamIn* in) |
| 85 | { |
| 86 | delete in; |
| 87 | } |
| 88 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | status_t AudioHardwareStub::setVoiceVolume(float volume) |
| 90 | { |
| 91 | return NO_ERROR; |
| 92 | } |
| 93 | |
| 94 | status_t AudioHardwareStub::setMasterVolume(float volume) |
| 95 | { |
| 96 | return NO_ERROR; |
| 97 | } |
| 98 | |
| 99 | status_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 | |
| 111 | status_t AudioHardwareStub::dump(int fd, const Vector<String16>& args) |
| 112 | { |
| 113 | dumpInternals(fd, args); |
| 114 | return NO_ERROR; |
| 115 | } |
| 116 | |
| 117 | // ---------------------------------------------------------------------------- |
| 118 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 119 | status_t AudioStreamOutStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | { |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 121 | if (pFormat) *pFormat = format(); |
| 122 | if (pChannels) *pChannels = channels(); |
| 123 | if (pRate) *pRate = sampleRate(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 125 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes) |
| 129 | { |
| 130 | // fake timing for audio output |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 131 | usleep(bytes * 1000000 / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | return bytes; |
| 133 | } |
| 134 | |
| 135 | status_t AudioStreamOutStub::standby() |
| 136 | { |
| 137 | return NO_ERROR; |
| 138 | } |
| 139 | |
| 140 | status_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()); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 148 | snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Eric Laurent | 764db96 | 2009-08-04 06:17:43 -0700 | [diff] [blame] | 155 | String8 AudioStreamOutStub::getParameters(const String8& keys) |
| 156 | { |
| 157 | AudioParameter param = AudioParameter(keys); |
| 158 | return param.toString(); |
| 159 | } |
| 160 | |
Eric Laurent | e9ed272 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 161 | status_t AudioStreamOutStub::getRenderPosition(uint32_t *dspFrames) |
| 162 | { |
| 163 | return INVALID_OPERATION; |
| 164 | } |
| 165 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | // ---------------------------------------------------------------------------- |
| 167 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 168 | status_t AudioStreamInStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate, |
Glenn Kasten | d5ea969 | 2010-03-05 12:18:01 -0800 | [diff] [blame] | 169 | AudioSystem::audio_in_acoustics acoustics) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | { |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 171 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes) |
| 175 | { |
| 176 | // fake timing for audio input |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 177 | usleep(bytes * 1000000 / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | memset(buffer, 0, bytes); |
| 179 | return bytes; |
| 180 | } |
| 181 | |
| 182 | status_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); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 193 | snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Eric Laurent | 764db96 | 2009-08-04 06:17:43 -0700 | [diff] [blame] | 201 | String8 AudioStreamInStub::getParameters(const String8& keys) |
| 202 | { |
| 203 | AudioParameter param = AudioParameter(keys); |
| 204 | return param.toString(); |
| 205 | } |
| 206 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | // ---------------------------------------------------------------------------- |
| 208 | |
| 209 | }; // namespace android |