summaryrefslogtreecommitdiffstats
path: root/media/libmedia
diff options
context:
space:
mode:
authorHaynes Mathew George <hgeorge@codeaurora.org>2014-01-08 13:59:53 -0800
committerEric Laurent <elaurent@google.com>2014-03-06 18:00:39 -0800
commit2048c2292c0466b184fb8f67c91f4d0ab9f5c3f3 (patch)
tree126fcbfff298dd8e0f8ddb834c93c8850b8654ac /media/libmedia
parenta11111f9135c98cf4247bbd1a61d7df3053e549e (diff)
downloadframeworks_av-2048c2292c0466b184fb8f67c91f4d0ab9f5c3f3.zip
frameworks_av-2048c2292c0466b184fb8f67c91f4d0ab9f5c3f3.tar.gz
frameworks_av-2048c2292c0466b184fb8f67c91f4d0ab9f5c3f3.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: Ia42b8b8fd2ba8993dfcc9abca72da48d71d78d74
Diffstat (limited to 'media/libmedia')
-rw-r--r--media/libmedia/AudioTrack.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 11b0b89..e0e1a73 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -85,7 +85,8 @@ AudioTrack::AudioTrack()
: mStatus(NO_INIT),
mIsTimed(false),
mPreviousPriority(ANDROID_PRIORITY_NORMAL),
- mPreviousSchedulingGroup(SP_DEFAULT)
+ mPreviousSchedulingGroup(SP_DEFAULT),
+ mPausedPosition(0)
{
}
@@ -106,7 +107,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,
@@ -131,7 +133,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,
@@ -529,6 +532,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)
@@ -747,6 +760,12 @@ status_t AudioTrack::getPosition(uint32_t *position) const
if (isOffloaded()) {
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);