3 ** Copyright 2007, The Android Open Source Project
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
9 ** http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <cutils/properties.h>
21 //#define LOG_NDEBUG 0
23 #define LOG_TAG "AudioHardwareInterface"
24 #include <utils/Log.h>
25 #include <utils/String8.h>
27 #include "AudioHardwareStub.h"
28 #include "AudioHardwareGeneric.h"
30 #ifdef ENABLE_AUDIO_DUMP
31 #include "AudioDumpInterface.h"
35 // change to 1 to log routing calls
36 #define LOG_ROUTING_CALLS 1
38 namespace android_audio_legacy {
41 static const char* routingModeStrings[] =
52 static const char* routeNone = "NONE";
54 static const char* displayMode(int mode)
56 if ((mode < AudioSystem::MODE_INVALID) || (mode >= AudioSystem::NUM_MODES))
57 return routingModeStrings[0];
58 return routingModeStrings[mode+3];
62 // ----------------------------------------------------------------------------
64 AudioHardwareInterface* AudioHardwareInterface::create()
69 AudioStreamOut::~AudioStreamOut()
73 // default implementation is unsupported
74 status_t AudioStreamOut::getNextWriteTimestamp(int64_t *timestamp)
76 return INVALID_OPERATION;
79 AudioStreamIn::~AudioStreamIn() {}
81 AudioHardwareBase::AudioHardwareBase()
86 status_t AudioHardwareBase::setMode(int mode)
89 ALOGD("setMode(%s)", displayMode(mode));
91 if ((mode < 0) || (mode >= AudioSystem::NUM_MODES))
94 return ALREADY_EXISTS;
99 // default implementation
100 status_t AudioHardwareBase::setParameters(const String8& keyValuePairs)
105 // default implementation
106 String8 AudioHardwareBase::getParameters(const String8& keys)
108 AudioParameter param = AudioParameter(keys);
109 return param.toString();
112 // default implementation
113 size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
115 if (sampleRate != 8000) {
116 ALOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
119 if (format != AudioSystem::PCM_16_BIT) {
120 ALOGW("getInputBufferSize bad format: %d", format);
123 if (channelCount != 1) {
124 ALOGW("getInputBufferSize bad channel count: %d", channelCount);
131 // default implementation is unsupported
132 status_t AudioHardwareBase::getMasterVolume(float *volume)
134 return INVALID_OPERATION;
137 status_t AudioHardwareBase::dumpState(int fd, const Vector<String16>& args)
139 const size_t SIZE = 256;
142 snprintf(buffer, SIZE, "AudioHardwareBase::dumpState\n");
143 result.append(buffer);
144 snprintf(buffer, SIZE, "\tmMode: %d\n", mMode);
145 result.append(buffer);
146 ::write(fd, result.string(), result.size());
147 dump(fd, args); // Dump the state of the concrete child.
151 // default implementation calls its "without flags" counterpart
152 AudioStreamOut* AudioHardwareInterface::openOutputStreamWithFlags(uint32_t devices,
153 audio_output_flags_t flags,
156 uint32_t *sampleRate,
159 return openOutputStream(devices, format, channels, sampleRate, status);
162 // ----------------------------------------------------------------------------
164 }; // namespace android