diff options
author | Sean McNeil <sean.mcneil@windriver.com> | 2010-06-30 15:38:30 +0700 |
---|---|---|
committer | Sean McNeil <sean.mcneil@windriver.com> | 2010-06-30 15:38:30 +0700 |
commit | 32ab8445881430264971cf72f8eb758d380ca34e (patch) | |
tree | 4bbd8e16a478e1acaf6c9034ba22fb9f3e6ef2ad | |
parent | 7366cc2e7e8464ef05170648b92490ec3b582038 (diff) | |
download | alsa_sound-eclair.tar.gz |
Sync with master branch.eclair
Remove FM route support. Google has changed tactics.
Add flag for compiling A2DP.
Change-Id: Ic59c971206061c8c53f22d09811a0c1fe3e800ac
-rw-r--r-- | ALSAMixer.cpp | 1 | ||||
-rw-r--r-- | Android.mk | 4 | ||||
-rw-r--r-- | AudioHardwareALSA.h | 16 | ||||
-rw-r--r-- | AudioPolicyManagerALSA.cpp | 62 | ||||
-rw-r--r-- | AudioStreamInALSA.cpp | 16 | ||||
-rw-r--r-- | AudioStreamOutALSA.cpp | 17 | ||||
-rw-r--r-- | alsa_default.cpp | 6 |
7 files changed, 72 insertions, 50 deletions
diff --git a/ALSAMixer.cpp b/ALSAMixer.cpp index 883edf1..8bae00a 100644 --- a/ALSAMixer.cpp +++ b/ALSAMixer.cpp @@ -74,7 +74,6 @@ mixerProp[][SND_PCM_STREAM_LAST+1] = { ALSA_PROP(AudioSystem::DEVICE_OUT_WIRED_HEADSET, "headset", "Headphone", "Capture"), ALSA_PROP(AudioSystem::DEVICE_OUT_BLUETOOTH_SCO, "bluetooth.sco", "Bluetooth", "Bluetooth Capture"), ALSA_PROP(AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP, "bluetooth.a2dp", "Bluetooth A2DP", "Bluetooth A2DP Capture"), - ALSA_PROP(AudioSystem::DEVICE_OUT_FM_HEADPHONE, "fm", "FM", ""), ALSA_PROP(static_cast<AudioSystem::audio_devices>(0), "", NULL, NULL) }; @@ -47,6 +47,10 @@ endif LOCAL_CFLAGS := -D_POSIX_SOURCE +ifeq ($(BOARD_HAVE_BLUETOOTH),true) + LOCAL_CFLAGS += -DWITH_A2DP +endif + LOCAL_SRC_FILES := AudioPolicyManagerALSA.cpp LOCAL_MODULE := libaudiopolicy diff --git a/AudioHardwareALSA.h b/AudioHardwareALSA.h index d2a9bec..e08fade 100644 --- a/AudioHardwareALSA.h +++ b/AudioHardwareALSA.h @@ -199,8 +199,15 @@ public: return ALSAStreamOps::getParameters(keys); } + // return the number of audio frames written by the audio dsp to DAC since + // the output has exited standby + virtual status_t getRenderPosition(uint32_t *dspFrames); + status_t open(int mode); status_t close(); + +private: + uint32_t mFrameCount; }; class AudioStreamInALSA : public AudioStreamIn, public ALSAStreamOps @@ -248,12 +255,21 @@ public: return ALSAStreamOps::getParameters(keys); } + // Return the amount of input frames lost in the audio driver since the last call of this function. + // Audio driver is expected to reset the value to 0 and restart counting upon returning the current value by this function call. + // Such loss typically occurs when the user space process is blocked longer than the capacity of audio driver buffers. + // Unit: the number of input audio frames + virtual unsigned int getInputFramesLost() const; + status_t setAcousticParams(void* params); status_t open(int mode); status_t close(); private: + void resetFramesLost(); + + unsigned int mFramesLost; AudioSystem::audio_in_acoustics mAcoustics; }; diff --git a/AudioPolicyManagerALSA.cpp b/AudioPolicyManagerALSA.cpp index b7808c9..d528e97 100644 --- a/AudioPolicyManagerALSA.cpp +++ b/AudioPolicyManagerALSA.cpp @@ -214,6 +214,7 @@ status_t AudioPolicyManagerALSA::setDeviceConnectionState(AudioSystem::audio_dev mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_DTMF)) { newDevice = device; } +#ifdef SUPPORT_DEVICE_OUT_TTY } else if (device == AudioSystem::DEVICE_OUT_TTY) { LOGV("setDeviceConnectionState() tty device"); // if connecting a wired headset, we check the following by order of priority @@ -225,24 +226,8 @@ status_t AudioPolicyManagerALSA::setDeviceConnectionState(AudioSystem::audio_dev mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_PHONE))) { newDevice = device; } - } else if (device == AudioSystem::DEVICE_OUT_FM_SPEAKER || - device == AudioSystem::DEVICE_OUT_FM_HEADPHONE) { - LOGV("setDeviceConnectionState() no mic headphone device"); - // if connecting a wired headset, we check the following by order of priority - // to request a routing change if necessary: - // 1: the strategy sonification is active on the hardware output: - // use device for strategy sonification - // 2: the strategy media is active on the hardware output: - // use device for strategy media - if ((getDeviceForStrategy(STRATEGY_SONIFICATION) & device) && - mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_SONIFICATION)){ - newDevice = getDeviceForStrategy(STRATEGY_SONIFICATION); - } else if ((getDeviceForStrategy(STRATEGY_MEDIA) == device) && - mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_MEDIA)){ - newDevice = device; - } +#endif // SUPPORT_DEVICE_OUT_TTY } - // request routing change if necessary setOutputDevice(mHardwareOutput, newDevice); } @@ -390,6 +375,7 @@ status_t AudioPolicyManagerALSA::setDeviceConnectionState(AudioSystem::audio_dev mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_DTMF)){ newDevice = getDeviceForStrategy(STRATEGY_DTMF); } +#ifdef SUPPORT_DEVICE_OUT_TTY } else if (device == AudioSystem::DEVICE_OUT_TTY) { LOGV("setDeviceConnectionState() tty device"); if (wasUsedforPhone && @@ -397,18 +383,10 @@ status_t AudioPolicyManagerALSA::setDeviceConnectionState(AudioSystem::audio_dev mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_PHONE))) { newDevice = getDeviceForStrategy(STRATEGY_PHONE); } - } else if (device == AudioSystem::DEVICE_OUT_FM_SPEAKER || - device == AudioSystem::DEVICE_OUT_FM_HEADPHONE) { - LOGV("setDeviceConnectionState() no mic headphone device"); - if (wasUsedForSonification && - mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_SONIFICATION)){ - newDevice = getDeviceForStrategy(STRATEGY_SONIFICATION); - } else if (wasUsedForMedia && - mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_MEDIA)){ - newDevice = getDeviceForStrategy(STRATEGY_MEDIA); - } +#endif // SUPPORT_DEVICE_OUT_TTY } } + // request routing change if necessary setOutputDevice(mHardwareOutput, newDevice); @@ -1345,8 +1323,10 @@ uint32_t AudioPolicyManagerALSA::getDeviceForStrategy(routing_strategy strategy) // FALL THROUGH default: // FORCE_NONE +#ifdef SUPPORT_DEVICE_OUT_TTY device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_TTY; if (device) break; +#endif // SUPPORT_DEVICE_OUT_TTY device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE; if (device) break; device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET; @@ -1362,7 +1342,7 @@ uint32_t AudioPolicyManagerALSA::getDeviceForStrategy(routing_strategy strategy) device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT; if (device) break; } - device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_FM_SPEAKER; + device = mAvailableOutputDevices; if (device) break; device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER; if (device == 0) { @@ -1396,22 +1376,16 @@ uint32_t AudioPolicyManagerALSA::getDeviceForStrategy(routing_strategy strategy) if (device2 == 0) { device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER; if (device2 == 0) { - device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_FM_HEADPHONE; - if (device2 == 0) { - device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_FM_SPEAKER; - if (device2 == 0) { - device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE; - if (device2 == 0) { - device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET; - if (device2 == 0) { - device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER; - if (device == 0) { - LOGE("getDeviceForStrategy() speaker device not found"); - } - } - } - } - } + device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE; + if (device2 == 0) { + device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET; + if (device2 == 0) { + device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER; + if (device == 0) { + LOGE("getDeviceForStrategy() speaker device not found"); + } + } + } } } } diff --git a/AudioStreamInALSA.cpp b/AudioStreamInALSA.cpp index 970dafd..32528a7 100644 --- a/AudioStreamInALSA.cpp +++ b/AudioStreamInALSA.cpp @@ -40,6 +40,7 @@ AudioStreamInALSA::AudioStreamInALSA(AudioHardwareALSA *parent, alsa_handle_t *handle, AudioSystem::audio_in_acoustics audio_acoustics) : ALSAStreamOps(parent, handle), + mFramesLost(0), mAcoustics(audio_acoustics) { acoustic_device_t *aDev = acoustics(); @@ -143,6 +144,21 @@ status_t AudioStreamInALSA::standby() return NO_ERROR; } +void AudioStreamInALSA::resetFramesLost() +{ + AutoMutex lock(mLock); + mFramesLost = 0; +} + +unsigned int AudioStreamInALSA::getInputFramesLost() const +{ + unsigned int count = mFramesLost; + // Stupid interface wants us to have a side effect of clearing the count + // but is defined as a const to prevent such a thing. + ((AudioStreamInALSA *)this)->resetFramesLost(); + return count; +} + status_t AudioStreamInALSA::setAcousticParams(void *params) { AutoMutex lock(mLock); diff --git a/AudioStreamOutALSA.cpp b/AudioStreamOutALSA.cpp index 781afbb..b295676 100644 --- a/AudioStreamOutALSA.cpp +++ b/AudioStreamOutALSA.cpp @@ -47,7 +47,8 @@ static const int DEFAULT_SAMPLE_RATE = ALSA_DEFAULT_SAMPLE_RATE; // ---------------------------------------------------------------------------- AudioStreamOutALSA::AudioStreamOutALSA(AudioHardwareALSA *parent, alsa_handle_t *handle) : - ALSAStreamOps(parent, handle) + ALSAStreamOps(parent, handle), + mFrameCount(0) { } @@ -109,8 +110,10 @@ ssize_t AudioStreamOutALSA::write(const void *buffer, size_t bytes) if (n) return static_cast<ssize_t>(n); } } - else + else { + mFrameCount += n; sent += static_cast<ssize_t>(snd_pcm_frames_to_bytes(mHandle->handle, n)); + } } while (mHandle->handle && sent < bytes); @@ -155,6 +158,8 @@ status_t AudioStreamOutALSA::standby() mPowerLock = false; } + mFrameCount = 0; + return NO_ERROR; } @@ -166,4 +171,12 @@ uint32_t AudioStreamOutALSA::latency() const return USEC_TO_MSEC (mHandle->latency); } +// return the number of audio frames written by the audio dsp to DAC since +// the output has exited standby +status_t AudioStreamOutALSA::getRenderPosition(uint32_t *dspFrames) +{ + *dspFrames = mFrameCount; + return NO_ERROR; +} + } // namespace android diff --git a/alsa_default.cpp b/alsa_default.cpp index 1951498..d437f37 100644 --- a/alsa_default.cpp +++ b/alsa_default.cpp @@ -138,7 +138,6 @@ static const device_suffix_t deviceSuffix[] = { {AudioSystem::DEVICE_OUT_BLUETOOTH_SCO, "_Bluetooth"}, {AudioSystem::DEVICE_OUT_WIRED_HEADSET, "_Headset"}, {AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP, "_Bluetooth-A2DP"}, - {AudioSystem::DEVICE_OUT_FM_HEADPHONE, "_FM"}, }; static const int deviceSuffixLen = (sizeof(deviceSuffix) @@ -278,8 +277,9 @@ status_t setHardwareParams(alsa_handle_t *handle) #endif // Make sure we have at least the size we originally wanted - err = snd_pcm_hw_params_set_buffer_size(handle->handle, hardwareParams, - bufferSize); + err = snd_pcm_hw_params_set_buffer_size_near(handle->handle, hardwareParams, + &bufferSize); + if (err < 0) { LOGE("Unable to set buffer size to %d: %s", (int)bufferSize, snd_strerror(err)); |