diff options
author | Sean McNeil <sean.mcneil@windriver.com> | 2010-06-25 13:07:06 +0700 |
---|---|---|
committer | Sean McNeil <sean.mcneil@windriver.com> | 2010-06-25 13:07:06 +0700 |
commit | 7ecd7d2a5a38c0ace23c88fb98fbdef056ad1847 (patch) | |
tree | e6537c704b43467dc15ad8c82d5ac08f8f14253d | |
parent | 305796ac898ef9c22190068bff61bb4c5cbedf8b (diff) | |
download | alsa_sound-7ecd7d2a5a38c0ace23c88fb98fbdef056ad1847.tar.gz |
Update for Froyo
Add new input stream method getInputFramesLost().
Add new output stream method getInputFramesLost().
-rw-r--r-- | AudioHardwareALSA.h | 16 | ||||
-rw-r--r-- | AudioStreamInALSA.cpp | 16 | ||||
-rw-r--r-- | AudioStreamOutALSA.cpp | 17 |
3 files changed, 47 insertions, 2 deletions
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/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 |