blob: b13cb1c072a85a4ceab01f71d6914428e49b1ecd [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"
26
27namespace android {
28
29// ----------------------------------------------------------------------------
30
31AudioHardwareStub::AudioHardwareStub() : mMicMute(false)
32{
33}
34
35AudioHardwareStub::~AudioHardwareStub()
36{
37}
38
39status_t AudioHardwareStub::initCheck()
40{
41 return NO_ERROR;
42}
43
44AudioStreamOut* AudioHardwareStub::openOutputStream(
45 int format, int channelCount, uint32_t sampleRate, status_t *status)
46{
47 AudioStreamOutStub* out = new AudioStreamOutStub();
48 status_t lStatus = out->set(format, channelCount, sampleRate);
49 if (status) {
50 *status = lStatus;
51 }
52 if (lStatus == NO_ERROR)
53 return out;
54 delete out;
55 return 0;
56}
57
58AudioStreamIn* AudioHardwareStub::openInputStream(
59 int format, int channelCount, uint32_t sampleRate,
60 status_t *status, AudioSystem::audio_in_acoustics acoustics)
61{
62 AudioStreamInStub* in = new AudioStreamInStub();
63 status_t lStatus = in->set(format, channelCount, sampleRate, acoustics);
64 if (status) {
65 *status = lStatus;
66 }
67 if (lStatus == NO_ERROR)
68 return in;
69 delete in;
70 return 0;
71}
72
73status_t AudioHardwareStub::setVoiceVolume(float volume)
74{
75 return NO_ERROR;
76}
77
78status_t AudioHardwareStub::setMasterVolume(float volume)
79{
80 return NO_ERROR;
81}
82
83status_t AudioHardwareStub::dumpInternals(int fd, const Vector<String16>& args)
84{
85 const size_t SIZE = 256;
86 char buffer[SIZE];
87 String8 result;
88 result.append("AudioHardwareStub::dumpInternals\n");
89 snprintf(buffer, SIZE, "\tmMicMute: %s\n", mMicMute? "true": "false");
90 result.append(buffer);
91 ::write(fd, result.string(), result.size());
92 return NO_ERROR;
93}
94
95status_t AudioHardwareStub::dump(int fd, const Vector<String16>& args)
96{
97 dumpInternals(fd, args);
98 return NO_ERROR;
99}
100
101// ----------------------------------------------------------------------------
102
103status_t AudioStreamOutStub::set(int format, int channels, uint32_t rate)
104{
105 // fix up defaults
106 if (format == 0) format = AudioSystem::PCM_16_BIT;
107 if (channels == 0) channels = channelCount();
108 if (rate == 0) rate = sampleRate();
109
110 if ((format == AudioSystem::PCM_16_BIT) &&
111 (channels == channelCount()) &&
112 (rate == sampleRate()))
113 return NO_ERROR;
114 return BAD_VALUE;
115}
116
117ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes)
118{
119 // fake timing for audio output
120 usleep(bytes * 1000000 / sizeof(int16_t) / channelCount() / sampleRate());
121 return bytes;
122}
123
124status_t AudioStreamOutStub::standby()
125{
126 return NO_ERROR;
127}
128
129status_t AudioStreamOutStub::dump(int fd, const Vector<String16>& args)
130{
131 const size_t SIZE = 256;
132 char buffer[SIZE];
133 String8 result;
134 snprintf(buffer, SIZE, "AudioStreamOutStub::dump\n");
135 snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate());
136 snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize());
137 snprintf(buffer, SIZE, "\tchannel count: %d\n", channelCount());
138 snprintf(buffer, SIZE, "\tformat: %d\n", format());
139 result.append(buffer);
140 ::write(fd, result.string(), result.size());
141 return NO_ERROR;
142}
143
144// ----------------------------------------------------------------------------
145
146status_t AudioStreamInStub::set(int format, int channels, uint32_t rate,
147 AudioSystem::audio_in_acoustics acoustics)
148{
149 if ((format == AudioSystem::PCM_16_BIT) &&
150 (channels == channelCount()) &&
151 (rate == sampleRate()))
152 return NO_ERROR;
153 return BAD_VALUE;
154}
155
156ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes)
157{
158 // fake timing for audio input
159 usleep(bytes * 1000000 / sizeof(int16_t) / channelCount() / sampleRate());
160 memset(buffer, 0, bytes);
161 return bytes;
162}
163
164status_t AudioStreamInStub::dump(int fd, const Vector<String16>& args)
165{
166 const size_t SIZE = 256;
167 char buffer[SIZE];
168 String8 result;
169 snprintf(buffer, SIZE, "AudioStreamInStub::dump\n");
170 result.append(buffer);
171 snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate());
172 result.append(buffer);
173 snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize());
174 result.append(buffer);
175 snprintf(buffer, SIZE, "\tchannel count: %d\n", channelCount());
176 result.append(buffer);
177 snprintf(buffer, SIZE, "\tformat: %d\n", format());
178 result.append(buffer);
179 ::write(fd, result.string(), result.size());
180 return NO_ERROR;
181}
182
183// ----------------------------------------------------------------------------
184
185}; // namespace android