blob: 0ab4c60e536147a23fe844390be5adb44446f655 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/* //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 Sparksad216e52009-05-19 14:38:46 -070026#include <media/AudioRecord.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
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 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
59AudioStreamIn* AudioHardwareStub::openInputStream(
Dave Sparksad216e52009-05-19 14:38:46 -070060 int inputSource, int format, int channelCount, uint32_t sampleRate,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 status_t *status, AudioSystem::audio_in_acoustics acoustics)
62{
Dave Sparksad216e52009-05-19 14:38:46 -070063 // check for valid input source
Eric Laurent4bc035a2009-05-22 09:18:15 -070064 if ((inputSource < AudioRecord::DEFAULT_INPUT) ||
65 (inputSource >= AudioRecord::NUM_INPUT_SOURCES)) {
Dave Sparksad216e52009-05-19 14:38:46 -070066 return 0;
67 }
68
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 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 Project9066cfe2009-03-03 19:31:44 -080080status_t AudioHardwareStub::setVoiceVolume(float volume)
81{
82 return NO_ERROR;
83}
84
85status_t AudioHardwareStub::setMasterVolume(float volume)
86{
87 return NO_ERROR;
88}
89
90status_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
102status_t AudioHardwareStub::dump(int fd, const Vector<String16>& args)
103{
104 dumpInternals(fd, args);
105 return NO_ERROR;
106}
107
108// ----------------------------------------------------------------------------
109
110status_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
124ssize_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
131status_t AudioStreamOutStub::standby()
132{
133 return NO_ERROR;
134}
135
136status_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
153status_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
163ssize_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
171status_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