summaryrefslogtreecommitdiffstats
path: root/media/libmedia
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2013-10-16 15:35:35 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-10-16 15:35:35 -0700
commit7f8c397378a7ee5abd395413be71388ad36d3ed2 (patch)
tree3a41029ec403c6fd32aeb91aa699c05720db6f44 /media/libmedia
parentace8947dbcd18e86c6a089291ffe1ce32fb42508 (diff)
parent120a88471a607c85c4d60300d73c3be0a1e8f8c8 (diff)
downloadframeworks_av-7f8c397378a7ee5abd395413be71388ad36d3ed2.zip
frameworks_av-7f8c397378a7ee5abd395413be71388ad36d3ed2.tar.gz
frameworks_av-7f8c397378a7ee5abd395413be71388ad36d3ed2.tar.bz2
am 120a8847: Merge "AudioTrack: fix head position after restore" into klp-dev
* commit '120a88471a607c85c4d60300d73c3be0a1e8f8c8': AudioTrack: fix head position after restore
Diffstat (limited to 'media/libmedia')
-rw-r--r--media/libmedia/AudioTrack.cpp4
-rw-r--r--media/libmedia/AudioTrackShared.cpp21
2 files changed, 24 insertions, 1 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 37d50cf..507f9bc 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -1662,7 +1662,9 @@ status_t AudioTrack::restoreTrack_l(const char *from)
// if the new IAudioTrack is created, createTrack_l() will modify the
// following member variables: mAudioTrack, mCblkMemory and mCblk.
// It will also delete the strong references on previous IAudioTrack and IMemory
- size_t position = mProxy->getPosition();
+
+ // take the frames that will be lost by track recreation into account in saved position
+ size_t position = mProxy->getPosition() + mProxy->getFramesFilled();
mNewPosition = position + mUpdatePeriod;
size_t bufferPosition = mStaticProxy != NULL ? mStaticProxy->getBufferPosition() : 0;
result = createTrack_l(mStreamType,
diff --git a/media/libmedia/AudioTrackShared.cpp b/media/libmedia/AudioTrackShared.cpp
index 4fd92b2..da73d65 100644
--- a/media/libmedia/AudioTrackShared.cpp
+++ b/media/libmedia/AudioTrackShared.cpp
@@ -316,6 +316,27 @@ size_t ClientProxy::getMisalignment()
(mFrameCountP2 - 1);
}
+size_t ClientProxy::getFramesFilled() {
+ audio_track_cblk_t* cblk = mCblk;
+ int32_t front;
+ int32_t rear;
+
+ if (mIsOut) {
+ front = android_atomic_acquire_load(&cblk->u.mStreaming.mFront);
+ rear = cblk->u.mStreaming.mRear;
+ } else {
+ rear = android_atomic_acquire_load(&cblk->u.mStreaming.mRear);
+ front = cblk->u.mStreaming.mFront;
+ }
+ ssize_t filled = rear - front;
+ // pipe should not be overfull
+ if (!(0 <= filled && (size_t) filled <= mFrameCount)) {
+ ALOGE("Shared memory control block is corrupt (filled=%d); shutting down", filled);
+ return 0;
+ }
+ return (size_t)filled;
+}
+
// ---------------------------------------------------------------------------
void AudioTrackClientProxy::flush()