The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <math.h> |
| 18 | |
| 19 | #define LOG_NDEBUG 0 |
| 20 | #define LOG_TAG "A2dpAudioInterface" |
| 21 | #include <utils/Log.h> |
| 22 | #include <utils/String8.h> |
| 23 | |
| 24 | #include "A2dpAudioInterface.h" |
| 25 | #include "audio/liba2dp.h" |
| 26 | |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | // ---------------------------------------------------------------------------- |
| 31 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 32 | //AudioHardwareInterface* A2dpAudioInterface::createA2dpInterface() |
| 33 | //{ |
| 34 | // AudioHardwareInterface* hw = 0; |
| 35 | // |
| 36 | // hw = AudioHardwareInterface::create(); |
| 37 | // LOGD("new A2dpAudioInterface(hw: %p)", hw); |
| 38 | // hw = new A2dpAudioInterface(hw); |
| 39 | // return hw; |
| 40 | //} |
| 41 | |
| 42 | A2dpAudioInterface::A2dpAudioInterface(AudioHardwareInterface* hw) : |
| 43 | mOutput(0), mHardwareInterface(hw), mBluetoothEnabled(true) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | A2dpAudioInterface::~A2dpAudioInterface() |
| 48 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 49 | closeOutputStream((AudioStreamOut *)mOutput); |
| 50 | delete mHardwareInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | status_t A2dpAudioInterface::initCheck() |
| 54 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 55 | if (mHardwareInterface == 0) return NO_INIT; |
| 56 | return mHardwareInterface->initCheck(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | AudioStreamOut* A2dpAudioInterface::openOutputStream( |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 60 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 62 | if (!AudioSystem::isA2dpDevice((AudioSystem::audio_devices)devices)) { |
| 63 | LOGV("A2dpAudioInterface::openOutputStream() open HW device: %x", devices); |
| 64 | return mHardwareInterface->openOutputStream(devices, format, channels, sampleRate, status); |
| 65 | } |
| 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | status_t err = 0; |
| 68 | |
| 69 | // only one output stream allowed |
| 70 | if (mOutput) { |
| 71 | if (status) |
| 72 | *status = -1; |
| 73 | return NULL; |
| 74 | } |
| 75 | |
| 76 | // create new output stream |
| 77 | A2dpAudioStreamOut* out = new A2dpAudioStreamOut(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 78 | if ((err = out->set(devices, format, channels, sampleRate)) == NO_ERROR) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | mOutput = out; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 80 | mOutput->setBluetoothEnabled(mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | } else { |
| 82 | delete out; |
| 83 | } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 84 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | if (status) |
| 86 | *status = err; |
| 87 | return mOutput; |
| 88 | } |
| 89 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 90 | void A2dpAudioInterface::closeOutputStream(AudioStreamOut* out) { |
| 91 | if (mOutput == 0 || mOutput != out) { |
Eric Laurent | 351def2 | 2009-08-04 07:43:10 -0700 | [diff] [blame^] | 92 | mHardwareInterface->closeOutputStream(out); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 93 | } |
| 94 | else { |
| 95 | delete mOutput; |
| 96 | mOutput = 0; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | AudioStreamIn* A2dpAudioInterface::openInputStream( |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 102 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status, |
| 103 | AudioSystem::audio_in_acoustics acoustics) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 105 | return mHardwareInterface->openInputStream(devices, format, channels, sampleRate, status, acoustics); |
| 106 | } |
| 107 | |
| 108 | void A2dpAudioInterface::closeInputStream(AudioStreamIn* in) |
| 109 | { |
| 110 | return mHardwareInterface->closeInputStream(in); |
| 111 | } |
| 112 | |
| 113 | status_t A2dpAudioInterface::setMode(int mode) |
| 114 | { |
| 115 | return mHardwareInterface->setMode(mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | status_t A2dpAudioInterface::setMicMute(bool state) |
| 119 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 120 | return mHardwareInterface->setMicMute(state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | status_t A2dpAudioInterface::getMicMute(bool* state) |
| 124 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 125 | return mHardwareInterface->getMicMute(state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 128 | status_t A2dpAudioInterface::setParameters(const String8& keyValuePairs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 130 | AudioParameter param = AudioParameter(keyValuePairs); |
| 131 | String8 value; |
| 132 | String8 key; |
| 133 | status_t status = NO_ERROR; |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 134 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 135 | LOGV("setParameters() %s", keyValuePairs.string()); |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 136 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 137 | key = "bluetooth_enabled"; |
| 138 | if (param.get(key, value) == NO_ERROR) { |
| 139 | mBluetoothEnabled = (value == "true"); |
| 140 | if (mOutput) { |
| 141 | mOutput->setBluetoothEnabled(mBluetoothEnabled); |
| 142 | } |
| 143 | param.remove(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 146 | if (param.size()) { |
| 147 | status_t hwStatus = mHardwareInterface->setParameters(param.toString()); |
| 148 | if (status == NO_ERROR) { |
| 149 | status = hwStatus; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return status; |
| 154 | } |
| 155 | |
| 156 | String8 A2dpAudioInterface::getParameters(const String8& keys) |
| 157 | { |
| 158 | AudioParameter param = AudioParameter(keys); |
| 159 | AudioParameter a2dpParam = AudioParameter(); |
| 160 | String8 value; |
| 161 | String8 key; |
| 162 | |
| 163 | key = "bluetooth_enabled"; |
| 164 | if (param.get(key, value) == NO_ERROR) { |
| 165 | value = mBluetoothEnabled ? "true" : "false"; |
| 166 | a2dpParam.add(key, value); |
| 167 | param.remove(key); |
| 168 | } |
| 169 | |
| 170 | String8 keyValuePairs = a2dpParam.toString(); |
| 171 | |
| 172 | if (param.size()) { |
| 173 | keyValuePairs += ";"; |
| 174 | keyValuePairs += mHardwareInterface->getParameters(param.toString()); |
| 175 | } |
| 176 | |
| 177 | LOGV("getParameters() %s", keyValuePairs.string()); |
| 178 | return keyValuePairs; |
| 179 | } |
| 180 | |
| 181 | size_t A2dpAudioInterface::getInputBufferSize(uint32_t sampleRate, int format, int channelCount) |
| 182 | { |
| 183 | return mHardwareInterface->getInputBufferSize(sampleRate, format, channelCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | status_t A2dpAudioInterface::setVoiceVolume(float v) |
| 187 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 188 | return mHardwareInterface->setVoiceVolume(v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | status_t A2dpAudioInterface::setMasterVolume(float v) |
| 192 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 193 | return mHardwareInterface->setMasterVolume(v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | status_t A2dpAudioInterface::dump(int fd, const Vector<String16>& args) |
| 197 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 198 | return mHardwareInterface->dumpState(fd, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | // ---------------------------------------------------------------------------- |
| 202 | |
| 203 | A2dpAudioInterface::A2dpAudioStreamOut::A2dpAudioStreamOut() : |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 204 | mFd(-1), mStandby(true), mStartCount(0), mRetryCount(0), mData(NULL), |
| 205 | // assume BT enabled to start, this is safe because its only the |
| 206 | // enabled->disabled transition we are worried about |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 207 | mBluetoothEnabled(true), mDevice(0) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | { |
| 209 | // use any address by default |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 210 | strcpy(mA2dpAddress, "00:00:00:00:00:00"); |
| 211 | init(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | status_t A2dpAudioInterface::A2dpAudioStreamOut::set( |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 215 | uint32_t device, int *pFormat, uint32_t *pChannels, uint32_t *pRate) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 217 | int lFormat = pFormat ? *pFormat : 0; |
| 218 | uint32_t lChannels = pChannels ? *pChannels : 0; |
| 219 | uint32_t lRate = pRate ? *pRate : 0; |
| 220 | |
| 221 | LOGD("A2dpAudioStreamOut::set %x, %d, %d, %d\n", device, lFormat, lChannels, lRate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
| 223 | // fix up defaults |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 224 | if (lFormat == 0) lFormat = format(); |
| 225 | if (lChannels == 0) lChannels = channels(); |
| 226 | if (lRate == 0) lRate = sampleRate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | |
| 228 | // check values |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 229 | if ((lFormat != format()) || |
| 230 | (lChannels != channels()) || |
| 231 | (lRate != sampleRate())){ |
| 232 | if (pFormat) *pFormat = format(); |
| 233 | if (pChannels) *pChannels = channels(); |
| 234 | if (pRate) *pRate = sampleRate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | return BAD_VALUE; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 236 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 238 | if (pFormat) *pFormat = lFormat; |
| 239 | if (pChannels) *pChannels = lChannels; |
| 240 | if (pRate) *pRate = lRate; |
| 241 | |
| 242 | mDevice = device; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | return NO_ERROR; |
| 244 | } |
| 245 | |
| 246 | A2dpAudioInterface::A2dpAudioStreamOut::~A2dpAudioStreamOut() |
| 247 | { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 248 | LOGV("A2dpAudioStreamOut destructor"); |
| 249 | standby(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | close(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 251 | LOGV("A2dpAudioStreamOut destructor returning from close()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t bytes) |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 255 | { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 256 | Mutex::Autolock lock(mLock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 258 | size_t remaining = bytes; |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 259 | status_t status = -1; |
| 260 | |
| 261 | if (!mBluetoothEnabled) { |
| 262 | LOGW("A2dpAudioStreamOut::write(), but bluetooth disabled"); |
| 263 | goto Error; |
| 264 | } |
| 265 | |
| 266 | status = init(); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 267 | if (status < 0) |
| 268 | goto Error; |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | while (remaining > 0) { |
| 271 | status = a2dp_write(mData, buffer, remaining); |
| 272 | if (status <= 0) { |
| 273 | LOGE("a2dp_write failed err: %d\n", status); |
| 274 | goto Error; |
| 275 | } |
| 276 | remaining -= status; |
| 277 | buffer = ((char *)buffer) + status; |
| 278 | } |
| 279 | |
| 280 | mStandby = false; |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | return bytes; |
| 283 | |
| 284 | Error: |
| 285 | // Simulate audio output timing in case of error |
| 286 | usleep(bytes * 1000000 / frameSize() / sampleRate()); |
| 287 | |
| 288 | return status; |
| 289 | } |
| 290 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 291 | status_t A2dpAudioInterface::A2dpAudioStreamOut::init() |
| 292 | { |
| 293 | if (!mData) { |
| 294 | status_t status = a2dp_init(44100, 2, &mData); |
| 295 | if (status < 0) { |
| 296 | LOGE("a2dp_init failed err: %d\n", status); |
| 297 | mData = NULL; |
| 298 | return status; |
| 299 | } |
| 300 | a2dp_set_sink(mData, mA2dpAddress); |
| 301 | } |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | status_t A2dpAudioInterface::A2dpAudioStreamOut::standby() |
| 307 | { |
| 308 | int result = 0; |
| 309 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 310 | Mutex::Autolock lock(mLock); |
| 311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | if (!mStandby) { |
| 313 | result = a2dp_stop(mData); |
| 314 | if (result == 0) |
| 315 | mStandby = true; |
| 316 | } |
| 317 | |
| 318 | return result; |
| 319 | } |
| 320 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 321 | status_t A2dpAudioInterface::A2dpAudioStreamOut::setParameters(const String8& keyValuePairs) |
| 322 | { |
| 323 | AudioParameter param = AudioParameter(keyValuePairs); |
| 324 | String8 value; |
| 325 | String8 key = String8("a2dp_sink_address"); |
| 326 | status_t status = NO_ERROR; |
| 327 | int device; |
| 328 | LOGV("A2dpAudioStreamOut::setParameters() %s", keyValuePairs.string()); |
| 329 | |
| 330 | if (param.get(key, value) == NO_ERROR) { |
| 331 | if (value.length() != strlen("00:00:00:00:00:00")) { |
| 332 | status = BAD_VALUE; |
| 333 | } else { |
| 334 | setAddress(value.string()); |
| 335 | } |
| 336 | param.remove(key); |
| 337 | } |
| 338 | key = AudioParameter::keyRouting; |
| 339 | if (param.getInt(key, device) == NO_ERROR) { |
| 340 | if (AudioSystem::isA2dpDevice((AudioSystem::audio_devices)device)) { |
| 341 | mDevice = device; |
| 342 | status = NO_ERROR; |
| 343 | } else { |
| 344 | status = BAD_VALUE; |
| 345 | } |
| 346 | param.remove(key); |
| 347 | } |
| 348 | |
| 349 | if (param.size()) { |
| 350 | status = BAD_VALUE; |
| 351 | } |
| 352 | return status; |
| 353 | } |
| 354 | |
| 355 | String8 A2dpAudioInterface::A2dpAudioStreamOut::getParameters(const String8& keys) |
| 356 | { |
| 357 | AudioParameter param = AudioParameter(keys); |
| 358 | String8 value; |
| 359 | String8 key = String8("a2dp_sink_address"); |
| 360 | |
| 361 | if (param.get(key, value) == NO_ERROR) { |
| 362 | value = mA2dpAddress; |
| 363 | param.add(key, value); |
| 364 | } |
| 365 | key = AudioParameter::keyRouting; |
| 366 | if (param.get(key, value) == NO_ERROR) { |
| 367 | param.addInt(key, (int)mDevice); |
| 368 | } |
| 369 | |
| 370 | LOGV("A2dpAudioStreamOut::getParameters() %s", param.toString().string()); |
| 371 | return param.toString(); |
| 372 | } |
| 373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | status_t A2dpAudioInterface::A2dpAudioStreamOut::setAddress(const char* address) |
| 375 | { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 376 | Mutex::Autolock lock(mLock); |
| 377 | |
| 378 | if (strlen(address) != strlen("00:00:00:00:00:00")) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | return -EINVAL; |
| 380 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 381 | strcpy(mA2dpAddress, address); |
| 382 | if (mData) |
| 383 | a2dp_set_sink(mData, mA2dpAddress); |
| 384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | return NO_ERROR; |
| 386 | } |
| 387 | |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 388 | status_t A2dpAudioInterface::A2dpAudioStreamOut::setBluetoothEnabled(bool enabled) |
| 389 | { |
| 390 | LOGD("setBluetoothEnabled %d", enabled); |
| 391 | |
| 392 | Mutex::Autolock lock(mLock); |
| 393 | |
| 394 | mBluetoothEnabled = enabled; |
| 395 | if (!enabled) { |
| 396 | return close_l(); |
| 397 | } |
| 398 | return NO_ERROR; |
| 399 | } |
| 400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | status_t A2dpAudioInterface::A2dpAudioStreamOut::close() |
| 402 | { |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 403 | Mutex::Autolock lock(mLock); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 404 | LOGV("A2dpAudioStreamOut::close() calling close_l()"); |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 405 | return close_l(); |
| 406 | } |
| 407 | |
| 408 | status_t A2dpAudioInterface::A2dpAudioStreamOut::close_l() |
| 409 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | if (mData) { |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 411 | LOGV("A2dpAudioStreamOut::close_l() calling a2dp_cleanup(mData)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | a2dp_cleanup(mData); |
| 413 | mData = NULL; |
| 414 | } |
| 415 | return NO_ERROR; |
| 416 | } |
| 417 | |
| 418 | status_t A2dpAudioInterface::A2dpAudioStreamOut::dump(int fd, const Vector<String16>& args) |
| 419 | { |
| 420 | return NO_ERROR; |
| 421 | } |
| 422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | }; // namespace android |