1 /*
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 <cutils/properties.h>
19 #include <string.h>
20 #include <unistd.h>
21 //#define LOG_NDEBUG 0
22 
23 #define LOG_TAG "AudioHardwareInterface"
24 #include <utils/Log.h>
25 #include <utils/String8.h>
26 
27 #include "AudioHardwareStub.h"
28 #include "AudioHardwareGeneric.h"
29 
30 #ifdef ENABLE_AUDIO_DUMP
31 #include "AudioDumpInterface.h"
32 #endif
33 
34 
35 // change to 1 to log routing calls
36 #define LOG_ROUTING_CALLS 1
37 
38 namespace android_audio_legacy {
39 
40 #if LOG_ROUTING_CALLS
41 static const char* routingModeStrings[] =
42 {
43     "OUT OF RANGE",
44     "INVALID",
45     "CURRENT",
46     "NORMAL",
47     "RINGTONE",
48     "IN_CALL",
49     "IN_COMMUNICATION"
50 };
51 
52 static const char* routeNone = "NONE";
53 
displayMode(int mode)54 static const char* displayMode(int mode)
55 {
56     if ((mode < AudioSystem::MODE_INVALID) || (mode >= AudioSystem::NUM_MODES))
57         return routingModeStrings[0];
58     return routingModeStrings[mode+3];
59 }
60 #endif
61 
62 // ----------------------------------------------------------------------------
63 
create()64 AudioHardwareInterface* AudioHardwareInterface::create()
65 {
66     return NULL;
67 }
68 
~AudioStreamOut()69 AudioStreamOut::~AudioStreamOut()
70 {
71 }
72 
73 // default implementation is unsupported
getNextWriteTimestamp(int64_t * timestamp)74 status_t AudioStreamOut::getNextWriteTimestamp(int64_t *timestamp)
75 {
76     return INVALID_OPERATION;
77 }
78 
~AudioStreamIn()79 AudioStreamIn::~AudioStreamIn() {}
80 
AudioHardwareBase()81 AudioHardwareBase::AudioHardwareBase()
82 {
83     mMode = 0;
84 }
85 
setMode(int mode)86 status_t AudioHardwareBase::setMode(int mode)
87 {
88 #if LOG_ROUTING_CALLS
89     ALOGD("setMode(%s)", displayMode(mode));
90 #endif
91     if ((mode < 0) || (mode >= AudioSystem::NUM_MODES))
92         return BAD_VALUE;
93     if (mMode == mode)
94         return ALREADY_EXISTS;
95     mMode = mode;
96     return NO_ERROR;
97 }
98 
99 // default implementation
setParameters(const String8 & keyValuePairs)100 status_t AudioHardwareBase::setParameters(const String8& keyValuePairs)
101 {
102     return NO_ERROR;
103 }
104 
105 // default implementation
getParameters(const String8 & keys)106 String8 AudioHardwareBase::getParameters(const String8& keys)
107 {
108     AudioParameter param = AudioParameter(keys);
109     return param.toString();
110 }
111 
112 // default implementation
getInputBufferSize(uint32_t sampleRate,int format,int channelCount)113 size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
114 {
115     if (sampleRate != 8000) {
116         ALOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
117         return 0;
118     }
119     if (format != AudioSystem::PCM_16_BIT) {
120         ALOGW("getInputBufferSize bad format: %d", format);
121         return 0;
122     }
123     if (channelCount != 1) {
124         ALOGW("getInputBufferSize bad channel count: %d", channelCount);
125         return 0;
126     }
127 
128     return 320;
129 }
130 
131 // default implementation is unsupported
getMasterVolume(float * volume)132 status_t AudioHardwareBase::getMasterVolume(float *volume)
133 {
134     return INVALID_OPERATION;
135 }
136 
dumpState(int fd,const Vector<String16> & args)137 status_t AudioHardwareBase::dumpState(int fd, const Vector<String16>& args)
138 {
139     const size_t SIZE = 256;
140     char buffer[SIZE];
141     String8 result;
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.
148     return NO_ERROR;
149 }
150 
151 // default implementation calls its "without flags" counterpart
openOutputStreamWithFlags(uint32_t devices,audio_output_flags_t flags,int * format,uint32_t * channels,uint32_t * sampleRate,status_t * status)152 AudioStreamOut* AudioHardwareInterface::openOutputStreamWithFlags(uint32_t devices,
153                                           audio_output_flags_t flags,
154                                           int *format,
155                                           uint32_t *channels,
156                                           uint32_t *sampleRate,
157                                           status_t *status)
158 {
159     return openOutputStream(devices, format, channels, sampleRate, status);
160 }
161 
162 // ----------------------------------------------------------------------------
163 
164 }; // namespace android
165