AudioHardwareInterface.cpp revision b4696fc22ba822ed37bd2e3a19bc17514ccc79c8
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
38namespace android_audio_legacy {
39
40#if LOG_ROUTING_CALLS
41static const char* routingModeStrings[] =
42{
43    "OUT OF RANGE",
44    "INVALID",
45    "CURRENT",
46    "NORMAL",
47    "RINGTONE",
48    "IN_CALL",
49    "IN_COMMUNICATION"
50};
51
52static const char* routeNone = "NONE";
53
54static 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
64AudioHardwareInterface* AudioHardwareInterface::create()
65{
66    return NULL;
67}
68
69AudioStreamOut::~AudioStreamOut()
70{
71}
72
73AudioStreamIn::~AudioStreamIn() {}
74
75AudioHardwareBase::AudioHardwareBase()
76{
77    mMode = 0;
78}
79
80status_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
94status_t AudioHardwareBase::setParameters(const String8& keyValuePairs)
95{
96    return NO_ERROR;
97}
98
99// default implementation
100String8 AudioHardwareBase::getParameters(const String8& keys)
101{
102    AudioParameter param = AudioParameter(keys);
103    return param.toString();
104}
105
106// default implementation
107size_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
125status_t AudioHardwareBase::dumpState(int fd, const Vector<String16>& args)
126{
127    const size_t SIZE = 256;
128    char buffer[SIZE];
129    String8 result;
130    snprintf(buffer, SIZE, "AudioHardwareBase::dumpState\n");
131    result.append(buffer);
132    snprintf(buffer, SIZE, "\tmMode: %d\n", mMode);
133    result.append(buffer);
134    ::write(fd, result.string(), result.size());
135    dump(fd, args);  // Dump the state of the concrete child.
136    return NO_ERROR;
137}
138
139// ----------------------------------------------------------------------------
140
141}; // namespace android
142