OSDN Git Service

am 6a70518b: (-s ours) Rename LOGV(_IF) to ALOGV(_IF) DO NOT MERGE
[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 #ifdef WITH_A2DP
30 #include "A2dpAudioInterface.h"
31 #endif
32
33 #ifdef ENABLE_AUDIO_DUMP
34 #include "AudioDumpInterface.h"
35 #endif
36
37
38 // change to 1 to log routing calls
39 #define LOG_ROUTING_CALLS 1
40
41 namespace android_audio_legacy {
42
43 #if LOG_ROUTING_CALLS
44 static const char* routingModeStrings[] =
45 {
46     "OUT OF RANGE",
47     "INVALID",
48     "CURRENT",
49     "NORMAL",
50     "RINGTONE",
51     "IN_CALL",
52     "IN_COMMUNICATION"
53 };
54
55 static const char* routeNone = "NONE";
56
57 static const char* displayMode(int mode)
58 {
59     if ((mode < AudioSystem::MODE_INVALID) || (mode >= AudioSystem::NUM_MODES))
60         return routingModeStrings[0];
61     return routingModeStrings[mode+3];
62 }
63 #endif
64
65 // ----------------------------------------------------------------------------
66
67 AudioHardwareInterface* AudioHardwareInterface::create()
68 {
69     return NULL;
70 }
71
72 AudioStreamOut::~AudioStreamOut()
73 {
74 }
75
76 // default implementation is unsupported
77 status_t AudioStreamOut::getNextWriteTimestamp(int64_t *timestamp)
78 {
79     return INVALID_OPERATION;
80 }
81
82 AudioStreamIn::~AudioStreamIn() {}
83
84 AudioHardwareBase::AudioHardwareBase()
85 {
86     mMode = 0;
87 }
88
89 status_t AudioHardwareBase::setMode(int mode)
90 {
91 #if LOG_ROUTING_CALLS
92     LOGD("setMode(%s)", displayMode(mode));
93 #endif
94     if ((mode < 0) || (mode >= AudioSystem::NUM_MODES))
95         return BAD_VALUE;
96     if (mMode == mode)
97         return ALREADY_EXISTS;
98     mMode = mode;
99     return NO_ERROR;
100 }
101
102 // default implementation
103 status_t AudioHardwareBase::setParameters(const String8& keyValuePairs)
104 {
105     return NO_ERROR;
106 }
107
108 // default implementation
109 String8 AudioHardwareBase::getParameters(const String8& keys)
110 {
111     AudioParameter param = AudioParameter(keys);
112     return param.toString();
113 }
114
115 // default implementation
116 size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
117 {
118     if (sampleRate != 8000) {
119         LOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
120         return 0;
121     }
122     if (format != AudioSystem::PCM_16_BIT) {
123         LOGW("getInputBufferSize bad format: %d", format);
124         return 0;
125     }
126     if (channelCount != 1) {
127         LOGW("getInputBufferSize bad channel count: %d", channelCount);
128         return 0;
129     }
130
131     return 320;
132 }
133
134 // default implementation is unsupported
135 status_t AudioHardwareBase::getMasterVolume(float *volume)
136 {
137     return INVALID_OPERATION;
138 }
139
140 status_t AudioHardwareBase::dumpState(int fd, const Vector<String16>& args)
141 {
142     const size_t SIZE = 256;
143     char buffer[SIZE];
144     String8 result;
145     snprintf(buffer, SIZE, "AudioHardwareBase::dumpState\n");
146     result.append(buffer);
147     snprintf(buffer, SIZE, "\tmMode: %d\n", mMode);
148     result.append(buffer);
149     ::write(fd, result.string(), result.size());
150     dump(fd, args);  // Dump the state of the concrete child.
151     return NO_ERROR;
152 }
153
154 // ----------------------------------------------------------------------------
155
156 }; // namespace android