xref: /aosp_15_r20/hardware/libhardware_legacy/audio/AudioHardwareStub.cpp (revision 79330504eb3d14022296e3b041867f86289dd52c)
1*79330504STreehugger Robot /* //device/servers/AudioFlinger/AudioHardwareStub.cpp
2*79330504STreehugger Robot **
3*79330504STreehugger Robot ** Copyright 2007, The Android Open Source Project
4*79330504STreehugger Robot **
5*79330504STreehugger Robot ** Licensed under the Apache License, Version 2.0 (the "License");
6*79330504STreehugger Robot ** you may not use this file except in compliance with the License.
7*79330504STreehugger Robot ** You may obtain a copy of the License at
8*79330504STreehugger Robot **
9*79330504STreehugger Robot **     http://www.apache.org/licenses/LICENSE-2.0
10*79330504STreehugger Robot **
11*79330504STreehugger Robot ** Unless required by applicable law or agreed to in writing, software
12*79330504STreehugger Robot ** distributed under the License is distributed on an "AS IS" BASIS,
13*79330504STreehugger Robot ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*79330504STreehugger Robot ** See the License for the specific language governing permissions and
15*79330504STreehugger Robot ** limitations under the License.
16*79330504STreehugger Robot */
17*79330504STreehugger Robot 
18*79330504STreehugger Robot #include <stdint.h>
19*79330504STreehugger Robot #include <sys/types.h>
20*79330504STreehugger Robot 
21*79330504STreehugger Robot #include <stdlib.h>
22*79330504STreehugger Robot #include <unistd.h>
23*79330504STreehugger Robot #include <utils/String8.h>
24*79330504STreehugger Robot 
25*79330504STreehugger Robot #include "AudioHardwareStub.h"
26*79330504STreehugger Robot #include <media/AudioRecord.h>
27*79330504STreehugger Robot 
28*79330504STreehugger Robot namespace android_audio_legacy {
29*79330504STreehugger Robot 
30*79330504STreehugger Robot // ----------------------------------------------------------------------------
31*79330504STreehugger Robot 
AudioHardwareStub()32*79330504STreehugger Robot AudioHardwareStub::AudioHardwareStub() : mMicMute(false)
33*79330504STreehugger Robot {
34*79330504STreehugger Robot }
35*79330504STreehugger Robot 
~AudioHardwareStub()36*79330504STreehugger Robot AudioHardwareStub::~AudioHardwareStub()
37*79330504STreehugger Robot {
38*79330504STreehugger Robot }
39*79330504STreehugger Robot 
initCheck()40*79330504STreehugger Robot status_t AudioHardwareStub::initCheck()
41*79330504STreehugger Robot {
42*79330504STreehugger Robot     return NO_ERROR;
43*79330504STreehugger Robot }
44*79330504STreehugger Robot 
openOutputStream(uint32_t devices,int * format,uint32_t * channels,uint32_t * sampleRate,status_t * status)45*79330504STreehugger Robot AudioStreamOut* AudioHardwareStub::openOutputStream(
46*79330504STreehugger Robot         uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status)
47*79330504STreehugger Robot {
48*79330504STreehugger Robot     AudioStreamOutStub* out = new AudioStreamOutStub();
49*79330504STreehugger Robot     status_t lStatus = out->set(format, channels, sampleRate);
50*79330504STreehugger Robot     if (status) {
51*79330504STreehugger Robot         *status = lStatus;
52*79330504STreehugger Robot     }
53*79330504STreehugger Robot     if (lStatus == NO_ERROR)
54*79330504STreehugger Robot         return out;
55*79330504STreehugger Robot     delete out;
56*79330504STreehugger Robot     return 0;
57*79330504STreehugger Robot }
58*79330504STreehugger Robot 
closeOutputStream(AudioStreamOut * out)59*79330504STreehugger Robot void AudioHardwareStub::closeOutputStream(AudioStreamOut* out)
60*79330504STreehugger Robot {
61*79330504STreehugger Robot     delete out;
62*79330504STreehugger Robot }
63*79330504STreehugger Robot 
openInputStream(uint32_t devices,int * format,uint32_t * channels,uint32_t * sampleRate,status_t * status,AudioSystem::audio_in_acoustics acoustics)64*79330504STreehugger Robot AudioStreamIn* AudioHardwareStub::openInputStream(
65*79330504STreehugger Robot         uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate,
66*79330504STreehugger Robot         status_t *status, AudioSystem::audio_in_acoustics acoustics)
67*79330504STreehugger Robot {
68*79330504STreehugger Robot     // check for valid input source
69*79330504STreehugger Robot     if (!AudioSystem::isInputDevice((AudioSystem::audio_devices)devices)) {
70*79330504STreehugger Robot         return 0;
71*79330504STreehugger Robot     }
72*79330504STreehugger Robot 
73*79330504STreehugger Robot     AudioStreamInStub* in = new AudioStreamInStub();
74*79330504STreehugger Robot     status_t lStatus = in->set(format, channels, sampleRate, acoustics);
75*79330504STreehugger Robot     if (status) {
76*79330504STreehugger Robot         *status = lStatus;
77*79330504STreehugger Robot     }
78*79330504STreehugger Robot     if (lStatus == NO_ERROR)
79*79330504STreehugger Robot         return in;
80*79330504STreehugger Robot     delete in;
81*79330504STreehugger Robot     return 0;
82*79330504STreehugger Robot }
83*79330504STreehugger Robot 
closeInputStream(AudioStreamIn * in)84*79330504STreehugger Robot void AudioHardwareStub::closeInputStream(AudioStreamIn* in)
85*79330504STreehugger Robot {
86*79330504STreehugger Robot     delete in;
87*79330504STreehugger Robot }
88*79330504STreehugger Robot 
setVoiceVolume(float volume)89*79330504STreehugger Robot status_t AudioHardwareStub::setVoiceVolume(float volume)
90*79330504STreehugger Robot {
91*79330504STreehugger Robot     return NO_ERROR;
92*79330504STreehugger Robot }
93*79330504STreehugger Robot 
setMasterVolume(float volume)94*79330504STreehugger Robot status_t AudioHardwareStub::setMasterVolume(float volume)
95*79330504STreehugger Robot {
96*79330504STreehugger Robot     return NO_ERROR;
97*79330504STreehugger Robot }
98*79330504STreehugger Robot 
dumpInternals(int fd,const Vector<String16> & args)99*79330504STreehugger Robot status_t AudioHardwareStub::dumpInternals(int fd, const Vector<String16>& args)
100*79330504STreehugger Robot {
101*79330504STreehugger Robot     const size_t SIZE = 256;
102*79330504STreehugger Robot     char buffer[SIZE];
103*79330504STreehugger Robot     String8 result;
104*79330504STreehugger Robot     result.append("AudioHardwareStub::dumpInternals\n");
105*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tmMicMute: %s\n", mMicMute? "true": "false");
106*79330504STreehugger Robot     result.append(buffer);
107*79330504STreehugger Robot     ::write(fd, result.string(), result.size());
108*79330504STreehugger Robot     return NO_ERROR;
109*79330504STreehugger Robot }
110*79330504STreehugger Robot 
dump(int fd,const Vector<String16> & args)111*79330504STreehugger Robot status_t AudioHardwareStub::dump(int fd, const Vector<String16>& args)
112*79330504STreehugger Robot {
113*79330504STreehugger Robot     dumpInternals(fd, args);
114*79330504STreehugger Robot     return NO_ERROR;
115*79330504STreehugger Robot }
116*79330504STreehugger Robot 
117*79330504STreehugger Robot // ----------------------------------------------------------------------------
118*79330504STreehugger Robot 
set(int * pFormat,uint32_t * pChannels,uint32_t * pRate)119*79330504STreehugger Robot status_t AudioStreamOutStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate)
120*79330504STreehugger Robot {
121*79330504STreehugger Robot     if (pFormat) *pFormat = format();
122*79330504STreehugger Robot     if (pChannels) *pChannels = channels();
123*79330504STreehugger Robot     if (pRate) *pRate = sampleRate();
124*79330504STreehugger Robot 
125*79330504STreehugger Robot     return NO_ERROR;
126*79330504STreehugger Robot }
127*79330504STreehugger Robot 
write(const void * buffer,size_t bytes)128*79330504STreehugger Robot ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes)
129*79330504STreehugger Robot {
130*79330504STreehugger Robot     // fake timing for audio output
131*79330504STreehugger Robot     usleep(bytes * 1000000 / sizeof(int16_t) /
132*79330504STreehugger Robot                audio_channel_count_from_out_mask(channels()) / sampleRate());
133*79330504STreehugger Robot     return bytes;
134*79330504STreehugger Robot }
135*79330504STreehugger Robot 
standby()136*79330504STreehugger Robot status_t AudioStreamOutStub::standby()
137*79330504STreehugger Robot {
138*79330504STreehugger Robot     return NO_ERROR;
139*79330504STreehugger Robot }
140*79330504STreehugger Robot 
dump(int fd,const Vector<String16> & args)141*79330504STreehugger Robot status_t AudioStreamOutStub::dump(int fd, const Vector<String16>& args)
142*79330504STreehugger Robot {
143*79330504STreehugger Robot     const size_t SIZE = 256;
144*79330504STreehugger Robot     char buffer[SIZE];
145*79330504STreehugger Robot     String8 result;
146*79330504STreehugger Robot     snprintf(buffer, SIZE, "AudioStreamOutStub::dump\n");
147*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate());
148*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize());
149*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tchannels: %d\n", channels());
150*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tformat: %d\n", format());
151*79330504STreehugger Robot     result.append(buffer);
152*79330504STreehugger Robot     ::write(fd, result.string(), result.size());
153*79330504STreehugger Robot     return NO_ERROR;
154*79330504STreehugger Robot }
155*79330504STreehugger Robot 
getParameters(const String8 & keys)156*79330504STreehugger Robot String8 AudioStreamOutStub::getParameters(const String8& keys)
157*79330504STreehugger Robot {
158*79330504STreehugger Robot     AudioParameter param = AudioParameter(keys);
159*79330504STreehugger Robot     return param.toString();
160*79330504STreehugger Robot }
161*79330504STreehugger Robot 
getRenderPosition(uint32_t * dspFrames)162*79330504STreehugger Robot status_t AudioStreamOutStub::getRenderPosition(uint32_t *dspFrames)
163*79330504STreehugger Robot {
164*79330504STreehugger Robot     return INVALID_OPERATION;
165*79330504STreehugger Robot }
166*79330504STreehugger Robot 
167*79330504STreehugger Robot // ----------------------------------------------------------------------------
168*79330504STreehugger Robot 
set(int * pFormat,uint32_t * pChannels,uint32_t * pRate,AudioSystem::audio_in_acoustics acoustics)169*79330504STreehugger Robot status_t AudioStreamInStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate,
170*79330504STreehugger Robot                 AudioSystem::audio_in_acoustics acoustics)
171*79330504STreehugger Robot {
172*79330504STreehugger Robot     return NO_ERROR;
173*79330504STreehugger Robot }
174*79330504STreehugger Robot 
read(void * buffer,ssize_t bytes)175*79330504STreehugger Robot ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes)
176*79330504STreehugger Robot {
177*79330504STreehugger Robot     // fake timing for audio input
178*79330504STreehugger Robot     usleep(bytes * 1000000 / sizeof(int16_t) /
179*79330504STreehugger Robot            audio_channel_count_from_in_mask(channels()) / sampleRate());
180*79330504STreehugger Robot     memset(buffer, 0, bytes);
181*79330504STreehugger Robot     return bytes;
182*79330504STreehugger Robot }
183*79330504STreehugger Robot 
dump(int fd,const Vector<String16> & args)184*79330504STreehugger Robot status_t AudioStreamInStub::dump(int fd, const Vector<String16>& args)
185*79330504STreehugger Robot {
186*79330504STreehugger Robot     const size_t SIZE = 256;
187*79330504STreehugger Robot     char buffer[SIZE];
188*79330504STreehugger Robot     String8 result;
189*79330504STreehugger Robot     snprintf(buffer, SIZE, "AudioStreamInStub::dump\n");
190*79330504STreehugger Robot     result.append(buffer);
191*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate());
192*79330504STreehugger Robot     result.append(buffer);
193*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize());
194*79330504STreehugger Robot     result.append(buffer);
195*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tchannels: %d\n", channels());
196*79330504STreehugger Robot     result.append(buffer);
197*79330504STreehugger Robot     snprintf(buffer, SIZE, "\tformat: %d\n", format());
198*79330504STreehugger Robot     result.append(buffer);
199*79330504STreehugger Robot     ::write(fd, result.string(), result.size());
200*79330504STreehugger Robot     return NO_ERROR;
201*79330504STreehugger Robot }
202*79330504STreehugger Robot 
getParameters(const String8 & keys)203*79330504STreehugger Robot String8 AudioStreamInStub::getParameters(const String8& keys)
204*79330504STreehugger Robot {
205*79330504STreehugger Robot     AudioParameter param = AudioParameter(keys);
206*79330504STreehugger Robot     return param.toString();
207*79330504STreehugger Robot }
208*79330504STreehugger Robot 
createAudioHardware(void)209*79330504STreehugger Robot AudioHardwareInterface* createAudioHardware(void) {
210*79330504STreehugger Robot     return new AudioHardwareStub();
211*79330504STreehugger Robot }
212*79330504STreehugger Robot 
213*79330504STreehugger Robot // ----------------------------------------------------------------------------
214*79330504STreehugger Robot 
215*79330504STreehugger Robot }; // namespace android
216