Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 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" |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 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 | |
Dima Zavin | e81531e | 2011-04-19 16:53:42 -0700 | [diff] [blame] | 38 | namespace android_audio_legacy { |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 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 | { |
Dima Zavin | e81531e | 2011-04-19 16:53:42 -0700 | [diff] [blame] | 66 | return NULL; |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | AudioStreamOut::~AudioStreamOut() |
| 70 | { |
| 71 | } |
| 72 | |
John Grossman | 5b71e6f | 2011-08-29 10:56:08 -0700 | [diff] [blame] | 73 | // default implementation is unsupported |
| 74 | status_t AudioStreamOut::getNextWriteTimestamp(int64_t *timestamp) |
| 75 | { |
| 76 | return INVALID_OPERATION; |
| 77 | } |
| 78 | |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 79 | AudioStreamIn::~AudioStreamIn() {} |
| 80 | |
| 81 | AudioHardwareBase::AudioHardwareBase() |
| 82 | { |
| 83 | mMode = 0; |
| 84 | } |
| 85 | |
| 86 | status_t AudioHardwareBase::setMode(int mode) |
| 87 | { |
| 88 | #if LOG_ROUTING_CALLS |
Steve Block | b381b93 | 2011-12-20 16:25:34 +0000 | [diff] [blame] | 89 | ALOGD("setMode(%s)", displayMode(mode)); |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 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 |
| 100 | status_t AudioHardwareBase::setParameters(const String8& keyValuePairs) |
| 101 | { |
| 102 | return NO_ERROR; |
| 103 | } |
| 104 | |
| 105 | // default implementation |
| 106 | String8 AudioHardwareBase::getParameters(const String8& keys) |
| 107 | { |
| 108 | AudioParameter param = AudioParameter(keys); |
| 109 | return param.toString(); |
| 110 | } |
| 111 | |
| 112 | // default implementation |
| 113 | size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount) |
| 114 | { |
| 115 | if (sampleRate != 8000) { |
Steve Block | 64cca04 | 2012-01-05 23:27:53 +0000 | [diff] [blame] | 116 | ALOGW("getInputBufferSize bad sampling rate: %d", sampleRate); |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | if (format != AudioSystem::PCM_16_BIT) { |
Steve Block | 64cca04 | 2012-01-05 23:27:53 +0000 | [diff] [blame] | 120 | ALOGW("getInputBufferSize bad format: %d", format); |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | if (channelCount != 1) { |
Steve Block | 64cca04 | 2012-01-05 23:27:53 +0000 | [diff] [blame] | 124 | ALOGW("getInputBufferSize bad channel count: %d", channelCount); |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | return 320; |
| 129 | } |
| 130 | |
John Grossman | 5b71e6f | 2011-08-29 10:56:08 -0700 | [diff] [blame] | 131 | // default implementation is unsupported |
John Grossman | 617c80a | 2011-08-22 13:25:06 -0700 | [diff] [blame] | 132 | status_t AudioHardwareBase::getMasterVolume(float *volume) |
| 133 | { |
| 134 | return INVALID_OPERATION; |
| 135 | } |
| 136 | |
Dima Zavin | f012159 | 2011-04-19 16:33:12 -0700 | [diff] [blame] | 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 | // ---------------------------------------------------------------------------- |
| 152 | |
| 153 | }; // namespace android |