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
28 namespace android_audio_legacy {
29
30 // ----------------------------------------------------------------------------
31
AudioHardwareStub()32 AudioHardwareStub::AudioHardwareStub() : mMicMute(false)
33 {
34 }
35
~AudioHardwareStub()36 AudioHardwareStub::~AudioHardwareStub()
37 {
38 }
39
initCheck()40 status_t AudioHardwareStub::initCheck()
41 {
42 return NO_ERROR;
43 }
44
openOutputStream(uint32_t devices,int * format,uint32_t * channels,uint32_t * sampleRate,status_t * status)45 AudioStreamOut* 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
closeOutputStream(AudioStreamOut * out)59 void AudioHardwareStub::closeOutputStream(AudioStreamOut* out)
60 {
61 delete out;
62 }
63
openInputStream(uint32_t devices,int * format,uint32_t * channels,uint32_t * sampleRate,status_t * status,AudioSystem::audio_in_acoustics acoustics)64 AudioStreamIn* 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
closeInputStream(AudioStreamIn * in)84 void AudioHardwareStub::closeInputStream(AudioStreamIn* in)
85 {
86 delete in;
87 }
88
setVoiceVolume(float volume)89 status_t AudioHardwareStub::setVoiceVolume(float volume)
90 {
91 return NO_ERROR;
92 }
93
setMasterVolume(float volume)94 status_t AudioHardwareStub::setMasterVolume(float volume)
95 {
96 return NO_ERROR;
97 }
98
dumpInternals(int fd,const Vector<String16> & args)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
dump(int fd,const Vector<String16> & args)111 status_t AudioHardwareStub::dump(int fd, const Vector<String16>& args)
112 {
113 dumpInternals(fd, args);
114 return NO_ERROR;
115 }
116
117 // ----------------------------------------------------------------------------
118
set(int * pFormat,uint32_t * pChannels,uint32_t * pRate)119 status_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
write(const void * buffer,size_t bytes)128 ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes)
129 {
130 // fake timing for audio output
131 usleep(bytes * 1000000 / sizeof(int16_t) /
132 audio_channel_count_from_out_mask(channels()) / sampleRate());
133 return bytes;
134 }
135
standby()136 status_t AudioStreamOutStub::standby()
137 {
138 return NO_ERROR;
139 }
140
dump(int fd,const Vector<String16> & args)141 status_t AudioStreamOutStub::dump(int fd, const Vector<String16>& args)
142 {
143 const size_t SIZE = 256;
144 char buffer[SIZE];
145 String8 result;
146 snprintf(buffer, SIZE, "AudioStreamOutStub::dump\n");
147 snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate());
148 snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize());
149 snprintf(buffer, SIZE, "\tchannels: %d\n", channels());
150 snprintf(buffer, SIZE, "\tformat: %d\n", format());
151 result.append(buffer);
152 ::write(fd, result.string(), result.size());
153 return NO_ERROR;
154 }
155
getParameters(const String8 & keys)156 String8 AudioStreamOutStub::getParameters(const String8& keys)
157 {
158 AudioParameter param = AudioParameter(keys);
159 return param.toString();
160 }
161
getRenderPosition(uint32_t * dspFrames)162 status_t AudioStreamOutStub::getRenderPosition(uint32_t *dspFrames)
163 {
164 return INVALID_OPERATION;
165 }
166
167 // ----------------------------------------------------------------------------
168
set(int * pFormat,uint32_t * pChannels,uint32_t * pRate,AudioSystem::audio_in_acoustics acoustics)169 status_t AudioStreamInStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate,
170 AudioSystem::audio_in_acoustics acoustics)
171 {
172 return NO_ERROR;
173 }
174
read(void * buffer,ssize_t bytes)175 ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes)
176 {
177 // fake timing for audio input
178 usleep(bytes * 1000000 / sizeof(int16_t) /
179 audio_channel_count_from_in_mask(channels()) / sampleRate());
180 memset(buffer, 0, bytes);
181 return bytes;
182 }
183
dump(int fd,const Vector<String16> & args)184 status_t AudioStreamInStub::dump(int fd, const Vector<String16>& args)
185 {
186 const size_t SIZE = 256;
187 char buffer[SIZE];
188 String8 result;
189 snprintf(buffer, SIZE, "AudioStreamInStub::dump\n");
190 result.append(buffer);
191 snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate());
192 result.append(buffer);
193 snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize());
194 result.append(buffer);
195 snprintf(buffer, SIZE, "\tchannels: %d\n", channels());
196 result.append(buffer);
197 snprintf(buffer, SIZE, "\tformat: %d\n", format());
198 result.append(buffer);
199 ::write(fd, result.string(), result.size());
200 return NO_ERROR;
201 }
202
getParameters(const String8 & keys)203 String8 AudioStreamInStub::getParameters(const String8& keys)
204 {
205 AudioParameter param = AudioParameter(keys);
206 return param.toString();
207 }
208
createAudioHardware(void)209 AudioHardwareInterface* createAudioHardware(void) {
210 return new AudioHardwareStub();
211 }
212
213 // ----------------------------------------------------------------------------
214
215 }; // namespace android
216