diff options
author | Haynes Mathew George <hgeorge@codeaurora.org> | 2014-01-08 13:59:53 -0800 |
---|---|---|
committer | Eric Laurent <elaurent@google.com> | 2014-03-06 11:38:38 -0800 |
commit | 7064fd2dcdfeafea53cd5a992bb78c413542f29f (patch) | |
tree | eb8961194a192128c7db06f5c0de50f9a72b93cd /media/libmedia | |
parent | 48588bdd9ec1102a5e96b9033d1ed8b8d6a3b3ba (diff) | |
download | frameworks_av-7064fd2dcdfeafea53cd5a992bb78c413542f29f.zip frameworks_av-7064fd2dcdfeafea53cd5a992bb78c413542f29f.tar.gz frameworks_av-7064fd2dcdfeafea53cd5a992bb78c413542f29f.tar.bz2 |
AudioTrack: When paused, return cached playback position
An offload output can be re-used between two audio tracks having
the same configuration. A timestamp query for a paused track
while the other is running would return an incorrect time.
To fix this, cache the playback position on a pause() and return
this time when requested until the track is resumed.
Bug: 12826612.
Change-Id: I324112ea9827e52fff53ef44cd8513c8d85a0bc4
Diffstat (limited to 'media/libmedia')
-rw-r--r-- | media/libmedia/AudioTrack.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index d25c40b..f353fac 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -99,7 +99,8 @@ AudioTrack::AudioTrack() : mStatus(NO_INIT), mIsTimed(false), mPreviousPriority(ANDROID_PRIORITY_NORMAL), - mPreviousSchedulingGroup(SP_DEFAULT) + mPreviousSchedulingGroup(SP_DEFAULT), + mPausedPosition(0) { } @@ -121,7 +122,8 @@ AudioTrack::AudioTrack( : mStatus(NO_INIT), mIsTimed(false), mPreviousPriority(ANDROID_PRIORITY_NORMAL), - mPreviousSchedulingGroup(SP_DEFAULT) + mPreviousSchedulingGroup(SP_DEFAULT), + mPausedPosition(0) { mStatus = set(streamType, sampleRate, format, channelMask, frameCount, flags, cbf, user, notificationFrames, @@ -147,7 +149,8 @@ AudioTrack::AudioTrack( : mStatus(NO_INIT), mIsTimed(false), mPreviousPriority(ANDROID_PRIORITY_NORMAL), - mPreviousSchedulingGroup(SP_DEFAULT) + mPreviousSchedulingGroup(SP_DEFAULT), + mPausedPosition(0) { mStatus = set(streamType, sampleRate, format, channelMask, 0 /*frameCount*/, flags, cbf, user, notificationFrames, @@ -551,6 +554,16 @@ void AudioTrack::pause() } mProxy->interrupt(); mAudioTrack->pause(); + + if (isOffloaded()) { + if (mOutput != 0) { + uint32_t halFrames; + // OffloadThread sends HAL pause in its threadLoop.. time saved + // here can be slightly off + AudioSystem::getRenderPosition(mOutput, &halFrames, &mPausedPosition); + ALOGV("AudioTrack::pause for offload, cache current position %u", mPausedPosition); + } + } } status_t AudioTrack::setVolume(float left, float right) @@ -770,6 +783,12 @@ status_t AudioTrack::getPosition(uint32_t *position) const if (isOffloaded_l()) { uint32_t dspFrames = 0; + if ((mState == STATE_PAUSED) || (mState == STATE_PAUSED_STOPPING)) { + ALOGV("getPosition called in paused state, return cached position %u", mPausedPosition); + *position = mPausedPosition; + return NO_ERROR; + } + if (mOutput != 0) { uint32_t halFrames; AudioSystem::getRenderPosition(mOutput, &halFrames, &dspFrames); |