OSDN Git Service

53c64b5a1d36a34a69ac6c396d55265bbba2d826
[android-x86/hardware-libhardware_legacy.git] / audio / AudioHardwareInterface.cpp
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
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
64 AudioHardwareInterface* AudioHardwareInterface::create()
65 {
66     return NULL;
67 }
68
69 AudioStreamOut::~AudioStreamOut()
70 {
71 }
72
73 AudioStreamIn::~AudioStreamIn() {}
74
75 AudioHardwareBase::AudioHardwareBase()
76 {
77     mMode = 0;
78 }
79
80 status_t AudioHardwareBase::setMode(int mode)
81 {
82 #if LOG_ROUTING_CALLS
83     ALOGD("setMode(%s)", displayMode(mode));
84 #endif
85     if ((mode < 0) || (mode >= AudioSystem::NUM_MODES))
86         return BAD_VALUE;
87     if (mMode == mode)
88         return ALREADY_EXISTS;
89     mMode = mode;
90     return NO_ERROR;
91 }
92
93 // default implementation
94 status_t AudioHardwareBase::setParameters(const String8& keyValuePairs)
95 {
96     return NO_ERROR;
97 }
98
99 // default implementation
100 String8 AudioHardwareBase::getParameters(const String8& keys)
101 {
102     AudioParameter param = AudioParameter(keys);
103     return param.toString();
104 }
105
106 // default implementation
107 size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
108 {
109     if (sampleRate != 8000) {
110         ALOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
111         return 0;
112     }
113     if (format != AudioSystem::PCM_16_BIT) {
114         ALOGW("getInputBufferSize bad format: %d", format);
115         return 0;
116     }
117     if (channelCount != 1) {
118         ALOGW("getInputBufferSize bad channel count: %d", channelCount);
119         return 0;
120     }
121
122     return 320;
123 }
124
125 status_t AudioHardwareBase::getMasterVolume(float *volume)
126 {
127     return INVALID_OPERATION;
128 }
129
130 status_t AudioHardwareBase::dumpState(int fd, const Vector<String16>& args)
131 {
132     const size_t SIZE = 256;
133     char buffer[SIZE];
134     String8 result;
135     snprintf(buffer, SIZE, "AudioHardwareBase::dumpState\n");
136     result.append(buffer);
137     snprintf(buffer, SIZE, "\tmMode: %d\n", mMode);
138     result.append(buffer);
139     ::write(fd, result.string(), result.size());
140     dump(fd, args);  // Dump the state of the concrete child.
141     return NO_ERROR;
142 }
143
144 // ----------------------------------------------------------------------------
145
146 }; // namespace android