blob: 60cce27e2517ad25680a126b589e5ecda106f65b [file] [log] [blame]
Dima Zavinf0121592011-04-19 16:33:12 -07001/*
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"
Dima Zavinf0121592011-04-19 16:33:12 -070029
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
Dima Zavine81531e2011-04-19 16:53:42 -070038namespace android_audio_legacy {
Dima Zavinf0121592011-04-19 16:33:12 -070039
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{
Dima Zavine81531e2011-04-19 16:53:42 -070066 return NULL;
Dima Zavinf0121592011-04-19 16:33:12 -070067}
68
69AudioStreamOut::~AudioStreamOut()
70{
71}
72
John Grossman5b71e6f2011-08-29 10:56:08 -070073// default implementation is unsupported
74status_t AudioStreamOut::getNextWriteTimestamp(int64_t *timestamp)
75{
76 return INVALID_OPERATION;
77}
78
Dima Zavinf0121592011-04-19 16:33:12 -070079AudioStreamIn::~AudioStreamIn() {}
80
81AudioHardwareBase::AudioHardwareBase()
82{
83 mMode = 0;
84}
85
86status_t AudioHardwareBase::setMode(int mode)
87{
88#if LOG_ROUTING_CALLS
Steve Blockb381b932011-12-20 16:25:34 +000089 ALOGD("setMode(%s)", displayMode(mode));
Dima Zavinf0121592011-04-19 16:33:12 -070090#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
100status_t AudioHardwareBase::setParameters(const String8& keyValuePairs)
101{
102 return NO_ERROR;
103}
104
105// default implementation
106String8 AudioHardwareBase::getParameters(const String8& keys)
107{
108 AudioParameter param = AudioParameter(keys);
109 return param.toString();
110}
111
112// default implementation
113size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
114{
115 if (sampleRate != 8000) {
Steve Block64cca042012-01-05 23:27:53 +0000116 ALOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
Dima Zavinf0121592011-04-19 16:33:12 -0700117 return 0;
118 }
119 if (format != AudioSystem::PCM_16_BIT) {
Steve Block64cca042012-01-05 23:27:53 +0000120 ALOGW("getInputBufferSize bad format: %d", format);
Dima Zavinf0121592011-04-19 16:33:12 -0700121 return 0;
122 }
123 if (channelCount != 1) {
Steve Block64cca042012-01-05 23:27:53 +0000124 ALOGW("getInputBufferSize bad channel count: %d", channelCount);
Dima Zavinf0121592011-04-19 16:33:12 -0700125 return 0;
126 }
127
128 return 320;
129}
130
John Grossman5b71e6f2011-08-29 10:56:08 -0700131// default implementation is unsupported
John Grossman617c80a2011-08-22 13:25:06 -0700132status_t AudioHardwareBase::getMasterVolume(float *volume)
133{
134 return INVALID_OPERATION;
135}
136
Dima Zavinf0121592011-04-19 16:33:12 -0700137status_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// ----------------------------------------------------------------------------
152
153}; // namespace android