The Android Open Source Project | 9066cfe | 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 | ad216e5 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 26 | #include <media/AudioRecord.h> |
The Android Open Source Project | 9066cfe | 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( |
| 46 | int format, int channelCount, uint32_t sampleRate, status_t *status) |
| 47 | { |
| 48 | AudioStreamOutStub* out = new AudioStreamOutStub(); |
| 49 | status_t lStatus = out->set(format, channelCount, sampleRate); |
| 50 | if (status) { |
| 51 | *status = lStatus; |
| 52 | } |
| 53 | if (lStatus == NO_ERROR) |
| 54 | return out; |
| 55 | delete out; |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | AudioStreamIn* AudioHardwareStub::openInputStream( |
Dave Sparks | ad216e5 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 60 | int inputSource, int format, int channelCount, uint32_t sampleRate, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | status_t *status, AudioSystem::audio_in_acoustics acoustics) |
| 62 | { |
Dave Sparks | ad216e5 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 63 | // check for valid input source |
Eric Laurent | 4bc035a | 2009-05-22 09:18:15 -0700 | [diff] [blame^] | 64 | if ((inputSource < AudioRecord::DEFAULT_INPUT) || |
| 65 | (inputSource >= AudioRecord::NUM_INPUT_SOURCES)) { |
Dave Sparks | ad216e5 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | AudioStreamInStub* in = new AudioStreamInStub(); |
| 70 | status_t lStatus = in->set(format, channelCount, sampleRate, acoustics); |
| 71 | if (status) { |
| 72 | *status = lStatus; |
| 73 | } |
| 74 | if (lStatus == NO_ERROR) |
| 75 | return in; |
| 76 | delete in; |
| 77 | return 0; |
| 78 | } |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | status_t AudioHardwareStub::setVoiceVolume(float volume) |
| 81 | { |
| 82 | return NO_ERROR; |
| 83 | } |
| 84 | |
| 85 | status_t AudioHardwareStub::setMasterVolume(float volume) |
| 86 | { |
| 87 | return NO_ERROR; |
| 88 | } |
| 89 | |
| 90 | status_t AudioHardwareStub::dumpInternals(int fd, const Vector<String16>& args) |
| 91 | { |
| 92 | const size_t SIZE = 256; |
| 93 | char buffer[SIZE]; |
| 94 | String8 result; |
| 95 | result.append("AudioHardwareStub::dumpInternals\n"); |
| 96 | snprintf(buffer, SIZE, "\tmMicMute: %s\n", mMicMute? "true": "false"); |
| 97 | result.append(buffer); |
| 98 | ::write(fd, result.string(), result.size()); |
| 99 | return NO_ERROR; |
| 100 | } |
| 101 | |
| 102 | status_t AudioHardwareStub::dump(int fd, const Vector<String16>& args) |
| 103 | { |
| 104 | dumpInternals(fd, args); |
| 105 | return NO_ERROR; |
| 106 | } |
| 107 | |
| 108 | // ---------------------------------------------------------------------------- |
| 109 | |
| 110 | status_t AudioStreamOutStub::set(int format, int channels, uint32_t rate) |
| 111 | { |
| 112 | // fix up defaults |
| 113 | if (format == 0) format = AudioSystem::PCM_16_BIT; |
| 114 | if (channels == 0) channels = channelCount(); |
| 115 | if (rate == 0) rate = sampleRate(); |
| 116 | |
| 117 | if ((format == AudioSystem::PCM_16_BIT) && |
| 118 | (channels == channelCount()) && |
| 119 | (rate == sampleRate())) |
| 120 | return NO_ERROR; |
| 121 | return BAD_VALUE; |
| 122 | } |
| 123 | |
| 124 | ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes) |
| 125 | { |
| 126 | // fake timing for audio output |
| 127 | usleep(bytes * 1000000 / sizeof(int16_t) / channelCount() / sampleRate()); |
| 128 | return bytes; |
| 129 | } |
| 130 | |
| 131 | status_t AudioStreamOutStub::standby() |
| 132 | { |
| 133 | return NO_ERROR; |
| 134 | } |
| 135 | |
| 136 | status_t AudioStreamOutStub::dump(int fd, const Vector<String16>& args) |
| 137 | { |
| 138 | const size_t SIZE = 256; |
| 139 | char buffer[SIZE]; |
| 140 | String8 result; |
| 141 | snprintf(buffer, SIZE, "AudioStreamOutStub::dump\n"); |
| 142 | snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); |
| 143 | snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); |
| 144 | snprintf(buffer, SIZE, "\tchannel count: %d\n", channelCount()); |
| 145 | snprintf(buffer, SIZE, "\tformat: %d\n", format()); |
| 146 | result.append(buffer); |
| 147 | ::write(fd, result.string(), result.size()); |
| 148 | return NO_ERROR; |
| 149 | } |
| 150 | |
| 151 | // ---------------------------------------------------------------------------- |
| 152 | |
| 153 | status_t AudioStreamInStub::set(int format, int channels, uint32_t rate, |
| 154 | AudioSystem::audio_in_acoustics acoustics) |
| 155 | { |
| 156 | if ((format == AudioSystem::PCM_16_BIT) && |
| 157 | (channels == channelCount()) && |
| 158 | (rate == sampleRate())) |
| 159 | return NO_ERROR; |
| 160 | return BAD_VALUE; |
| 161 | } |
| 162 | |
| 163 | ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes) |
| 164 | { |
| 165 | // fake timing for audio input |
| 166 | usleep(bytes * 1000000 / sizeof(int16_t) / channelCount() / sampleRate()); |
| 167 | memset(buffer, 0, bytes); |
| 168 | return bytes; |
| 169 | } |
| 170 | |
| 171 | status_t AudioStreamInStub::dump(int fd, const Vector<String16>& args) |
| 172 | { |
| 173 | const size_t SIZE = 256; |
| 174 | char buffer[SIZE]; |
| 175 | String8 result; |
| 176 | snprintf(buffer, SIZE, "AudioStreamInStub::dump\n"); |
| 177 | result.append(buffer); |
| 178 | snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); |
| 179 | result.append(buffer); |
| 180 | snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); |
| 181 | result.append(buffer); |
| 182 | snprintf(buffer, SIZE, "\tchannel count: %d\n", channelCount()); |
| 183 | result.append(buffer); |
| 184 | snprintf(buffer, SIZE, "\tformat: %d\n", format()); |
| 185 | result.append(buffer); |
| 186 | ::write(fd, result.string(), result.size()); |
| 187 | return NO_ERROR; |
| 188 | } |
| 189 | |
| 190 | // ---------------------------------------------------------------------------- |
| 191 | |
| 192 | }; // namespace android |