Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1 | /* AudioStreamOutALSA.cpp |
| 2 | ** |
| 3 | ** Copyright 2008-2009 Wind River Systems |
| 4 | ** Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 5 | ** |
| 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | ** you may not use this file except in compliance with the License. |
| 8 | ** You may obtain a copy of the License at |
| 9 | ** |
| 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | ** |
| 12 | ** Unless required by applicable law or agreed to in writing, software |
| 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | ** See the License for the specific language governing permissions and |
| 16 | ** limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #include <errno.h> |
| 20 | #include <stdarg.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <unistd.h> |
| 25 | #include <dlfcn.h> |
| 26 | #include <math.h> |
| 27 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 28 | #define LOG_TAG "AudioStreamOutALSA" |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 29 | //#define LOG_NDEBUG 0 |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 30 | #define LOG_NDDEBUG 0 |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 31 | #include <utils/Log.h> |
| 32 | #include <utils/String8.h> |
| 33 | |
| 34 | #include <cutils/properties.h> |
| 35 | #include <media/AudioRecord.h> |
| 36 | #include <hardware_legacy/power.h> |
| 37 | |
| 38 | #include "AudioHardwareALSA.h" |
| 39 | |
| 40 | #ifndef ALSA_DEFAULT_SAMPLE_RATE |
| 41 | #define ALSA_DEFAULT_SAMPLE_RATE 44100 // in Hz |
| 42 | #endif |
| 43 | |
| 44 | namespace android_audio_legacy |
| 45 | { |
| 46 | |
| 47 | // ---------------------------------------------------------------------------- |
| 48 | |
| 49 | static const int DEFAULT_SAMPLE_RATE = ALSA_DEFAULT_SAMPLE_RATE; |
| 50 | |
| 51 | // ---------------------------------------------------------------------------- |
| 52 | |
| 53 | AudioStreamOutALSA::AudioStreamOutALSA(AudioHardwareALSA *parent, alsa_handle_t *handle) : |
| 54 | ALSAStreamOps(parent, handle), |
| 55 | mParent(parent), |
| 56 | mFrameCount(0) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | AudioStreamOutALSA::~AudioStreamOutALSA() |
| 61 | { |
| 62 | close(); |
| 63 | } |
| 64 | |
| 65 | uint32_t AudioStreamOutALSA::channels() const |
| 66 | { |
| 67 | int c = ALSAStreamOps::channels(); |
| 68 | return c; |
| 69 | } |
| 70 | |
| 71 | status_t AudioStreamOutALSA::setVolume(float left, float right) |
| 72 | { |
| 73 | int vol; |
| 74 | float volume; |
| 75 | status_t status = NO_ERROR; |
| 76 | |
| 77 | volume = (left + right) / 2; |
| 78 | if (volume < 0.0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 79 | ALOGW("AudioSessionOutALSA::setVolume(%f) under 0.0, assuming 0.0\n", volume); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 80 | volume = 0.0; |
| 81 | } else if (volume > 1.0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 82 | ALOGW("AudioSessionOutALSA::setVolume(%f) over 1.0, assuming 1.0\n", volume); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 83 | volume = 1.0; |
| 84 | } |
| 85 | vol = lrint((volume * 0x2000)+0.5); |
| 86 | |
| 87 | if(!strcmp(mHandle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER) || |
| 88 | !strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 89 | ALOGD("setLpaVolume(%f)\n", volume); |
| 90 | ALOGD("Setting LPA volume to %d (available range is 0 to 100)\n", vol); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 91 | mHandle->module->setLpaVolume(vol); |
| 92 | return status; |
| 93 | } |
| 94 | else if(!strcmp(mHandle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL) || |
| 95 | !strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 96 | ALOGD("setCompressedVolume(%f)\n", volume); |
| 97 | ALOGD("Setting Compressed volume to %d (available range is 0 to 100)\n", vol); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 98 | mHandle->module->setCompressedVolume(vol); |
| 99 | return status; |
| 100 | } |
| 101 | else if(!strncmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL, |
| 102 | sizeof(mHandle->useCase)) || !strncmp(mHandle->useCase, |
| 103 | SND_USE_CASE_MOD_PLAY_VOIP, sizeof(mHandle->useCase))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 104 | ALOGV("Avoid Software volume by returning success\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 105 | return status; |
| 106 | } |
| 107 | return INVALID_OPERATION; |
| 108 | } |
| 109 | |
| 110 | ssize_t AudioStreamOutALSA::write(const void *buffer, size_t bytes) |
| 111 | { |
| 112 | int period_size; |
| 113 | char *use_case; |
| 114 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 115 | ALOGV("write:: buffer %p, bytes %d", buffer, bytes); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 116 | |
| 117 | snd_pcm_sframes_t n = 0; |
| 118 | size_t sent = 0; |
| 119 | status_t err; |
| 120 | |
| 121 | int write_pending = bytes; |
| 122 | |
| 123 | if((mHandle->handle == NULL) && (mHandle->rxHandle == NULL) && |
| 124 | (strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) && |
| 125 | (strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 126 | mParent->mLock.lock(); |
| 127 | /* PCM handle might be closed and reopened immediately to flush |
| 128 | * the buffers, recheck and break if PCM handle is valid */ |
| 129 | if (mHandle->handle == NULL && mHandle->rxHandle == NULL) { |
| 130 | snd_use_case_get(mHandle->ucMgr, "_verb", (const char **)&use_case); |
| 131 | if ((use_case == NULL) || (!strcmp(use_case, SND_USE_CASE_VERB_INACTIVE))) { |
| 132 | if(!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)){ |
| 133 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL,sizeof(mHandle->useCase)); |
| 134 | } |
| 135 | else { |
| 136 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_HIFI, sizeof(mHandle->useCase)); |
| 137 | } |
| 138 | } else { |
| 139 | if(!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP)) { |
| 140 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP,sizeof(mHandle->useCase)); |
| 141 | } else { |
| 142 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_PLAY_MUSIC, sizeof(mHandle->useCase)); |
| 143 | } |
| 144 | } |
| 145 | free(use_case); |
| 146 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 147 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 148 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 149 | if((mDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET)|| |
| 150 | (mDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)|| |
| 151 | (mDevices & AudioSystem::DEVICE_OUT_PROXY)) { |
| 152 | mDevices |= AudioSystem::DEVICE_OUT_PROXY; |
| 153 | mHandle->module->route(mHandle, mDevices , mParent->mode()); |
| 154 | }else |
| 155 | #endif |
| 156 | { |
| 157 | mHandle->module->route(mHandle, mDevices , AudioSystem::MODE_IN_COMMUNICATION); |
| 158 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 159 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 160 | } else if((mDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET)|| |
| 161 | (mDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)|| |
| 162 | (mDevices & AudioSystem::DEVICE_OUT_PROXY)) { |
| 163 | mDevices |= AudioSystem::DEVICE_OUT_PROXY; |
| 164 | mHandle->module->route(mHandle, mDevices , mParent->mode()); |
| 165 | #endif |
| 166 | } else { |
| 167 | |
| 168 | mHandle->module->route(mHandle, mDevices , mParent->mode()); |
| 169 | } |
| 170 | if (!strcmp(mHandle->useCase, SND_USE_CASE_VERB_HIFI) || |
| 171 | !strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) { |
| 172 | snd_use_case_set(mHandle->ucMgr, "_verb", mHandle->useCase); |
| 173 | } else { |
| 174 | snd_use_case_set(mHandle->ucMgr, "_enamod", mHandle->useCase); |
| 175 | } |
| 176 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 177 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 178 | err = mHandle->module->startVoipCall(mHandle); |
| 179 | } |
| 180 | else |
| 181 | mHandle->module->open(mHandle); |
| 182 | if(mHandle->handle == NULL) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 183 | ALOGE("write:: device open failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 184 | mParent->mLock.unlock(); |
| 185 | return 0; |
| 186 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 187 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 188 | if((mHandle->devices == AudioSystem::DEVICE_IN_ANLG_DOCK_HEADSET)|| |
| 189 | (mHandle->devices == AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET)){ |
| 190 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 191 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 192 | mParent->musbPlaybackState |= USBPLAYBACKBIT_VOIPCALL; |
| 193 | } else { |
| 194 | mParent->startUsbPlaybackIfNotStarted(); |
| 195 | mParent->musbPlaybackState |= USBPLAYBACKBIT_MUSIC; |
| 196 | } |
| 197 | } |
| 198 | #endif |
| 199 | } |
| 200 | mParent->mLock.unlock(); |
| 201 | } |
| 202 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 203 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 204 | if(((mDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET) || |
| 205 | (mDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)) && |
| 206 | (!mParent->musbPlaybackState)) { |
| 207 | mParent->mLock.lock(); |
| 208 | mParent->startUsbPlaybackIfNotStarted(); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 209 | ALOGD("Starting playback on USB"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 210 | if(!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL) || |
| 211 | !strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 212 | ALOGE("Setting VOIPCALL bit here, musbPlaybackState %d", mParent->musbPlaybackState); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 213 | mParent->musbPlaybackState |= USBPLAYBACKBIT_VOIPCALL; |
| 214 | }else{ |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 215 | ALOGD("enabling music, musbPlaybackState: %d ", mParent->musbPlaybackState); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 216 | mParent->musbPlaybackState |= USBPLAYBACKBIT_MUSIC; |
| 217 | } |
| 218 | mParent->mLock.unlock(); |
| 219 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 220 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 221 | |
| 222 | period_size = mHandle->periodSize; |
| 223 | do { |
| 224 | if (write_pending < period_size) { |
| 225 | write_pending = period_size; |
| 226 | } |
| 227 | if((mParent->mVoipStreamCount) && (mHandle->rxHandle != 0)) { |
| 228 | n = pcm_write(mHandle->rxHandle, |
| 229 | (char *)buffer + sent, |
| 230 | period_size); |
| 231 | } else if (mHandle->handle != 0){ |
| 232 | n = pcm_write(mHandle->handle, |
| 233 | (char *)buffer + sent, |
| 234 | period_size); |
| 235 | } |
| 236 | if (n < 0) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 237 | mParent->mLock.lock(); |
| 238 | ALOGE("pcm_write returned error %l, trying to recover\n", n); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 239 | pcm_close(mHandle->handle); |
| 240 | mHandle->handle = NULL; |
| 241 | if((!strncmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL, strlen(SND_USE_CASE_VERB_IP_VOICECALL))) || |
| 242 | (!strncmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP, strlen(SND_USE_CASE_MOD_PLAY_VOIP)))) { |
| 243 | pcm_close(mHandle->rxHandle); |
| 244 | mHandle->rxHandle = NULL; |
| 245 | mHandle->module->startVoipCall(mHandle); |
| 246 | } |
| 247 | else |
| 248 | mHandle->module->open(mHandle); |
| 249 | mParent->mLock.unlock(); |
| 250 | continue; |
| 251 | } |
| 252 | else { |
| 253 | mFrameCount += n; |
| 254 | sent += static_cast<ssize_t>((period_size)); |
| 255 | write_pending -= period_size; |
| 256 | } |
| 257 | |
| 258 | } while ((mHandle->handle||(mHandle->rxHandle && mParent->mVoipStreamCount)) && sent < bytes); |
| 259 | |
| 260 | return sent; |
| 261 | } |
| 262 | |
| 263 | status_t AudioStreamOutALSA::dump(int fd, const Vector<String16>& args) |
| 264 | { |
| 265 | return NO_ERROR; |
| 266 | } |
| 267 | |
| 268 | status_t AudioStreamOutALSA::open(int mode) |
| 269 | { |
| 270 | Mutex::Autolock autoLock(mParent->mLock); |
| 271 | |
| 272 | return ALSAStreamOps::open(mode); |
| 273 | } |
| 274 | |
| 275 | status_t AudioStreamOutALSA::close() |
| 276 | { |
| 277 | Mutex::Autolock autoLock(mParent->mLock); |
| 278 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 279 | ALOGD("close"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 280 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 281 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 282 | if((mParent->mVoipStreamCount)) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 283 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 284 | if(mParent->mVoipStreamCount == 1) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 285 | ALOGD("Deregistering VOIP Call bit, musbPlaybackState:%d, musbRecordingState: %d", |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 286 | mParent->musbPlaybackState, mParent->musbRecordingState); |
| 287 | mParent->musbPlaybackState &= ~USBPLAYBACKBIT_VOIPCALL; |
| 288 | mParent->musbRecordingState &= ~USBRECBIT_VOIPCALL; |
| 289 | mParent->closeUsbPlaybackIfNothingActive(); |
| 290 | mParent->closeUsbRecordingIfNothingActive(); |
| 291 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 292 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 293 | return NO_ERROR; |
| 294 | } |
| 295 | mParent->mVoipStreamCount = 0; |
| 296 | mParent->mVoipMicMute = 0; |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 297 | } |
| 298 | #ifdef QCOM_USBAUDIO_ENABLED |
| 299 | else if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 300 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_LPA))) { |
| 301 | mParent->musbPlaybackState &= ~USBPLAYBACKBIT_LPA; |
| 302 | } else { |
| 303 | mParent->musbPlaybackState &= ~USBPLAYBACKBIT_MUSIC; |
| 304 | } |
| 305 | |
| 306 | mParent->closeUsbPlaybackIfNothingActive(); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 307 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 308 | |
| 309 | ALSAStreamOps::close(); |
| 310 | |
| 311 | return NO_ERROR; |
| 312 | } |
| 313 | |
| 314 | status_t AudioStreamOutALSA::standby() |
| 315 | { |
| 316 | Mutex::Autolock autoLock(mParent->mLock); |
| 317 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 318 | ALOGD("standby"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 319 | |
| 320 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 321 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 322 | return NO_ERROR; |
| 323 | } |
| 324 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 325 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 326 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 327 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_LPA))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 328 | ALOGD("Deregistering LPA bit"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 329 | mParent->musbPlaybackState &= ~USBPLAYBACKBIT_LPA; |
| 330 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 331 | ALOGD("Deregistering MUSIC bit, musbPlaybackState: %d", mParent->musbPlaybackState); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 332 | mParent->musbPlaybackState &= ~USBPLAYBACKBIT_MUSIC; |
| 333 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 334 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 335 | |
| 336 | mHandle->module->standby(mHandle); |
| 337 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 338 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 339 | mParent->closeUsbPlaybackIfNothingActive(); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 340 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 341 | |
| 342 | mFrameCount = 0; |
| 343 | |
| 344 | return NO_ERROR; |
| 345 | } |
| 346 | |
| 347 | #define USEC_TO_MSEC(x) ((x + 999) / 1000) |
| 348 | |
| 349 | uint32_t AudioStreamOutALSA::latency() const |
| 350 | { |
| 351 | // Android wants latency in milliseconds. |
| 352 | return USEC_TO_MSEC (mHandle->latency); |
| 353 | } |
| 354 | |
| 355 | // return the number of audio frames written by the audio dsp to DAC since |
| 356 | // the output has exited standby |
| 357 | status_t AudioStreamOutALSA::getRenderPosition(uint32_t *dspFrames) |
| 358 | { |
| 359 | *dspFrames = mFrameCount; |
| 360 | return NO_ERROR; |
| 361 | } |
| 362 | |
| 363 | } // namespace android_audio_legacy |