Skip to content

Commit 2daf331

Browse files
jmtriviAndroid (Google) Code Review
authored andcommitted
Merge "Bug 4364249 Play position is 0 after flushing AudioTrack"
2 parents d912ec6 + 22cb204 commit 2daf331

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

include/media/AudioTrack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ class AudioTrack
481481
bool mMarkerReached;
482482
uint32_t mNewPosition;
483483
uint32_t mUpdatePeriod;
484+
bool mFlushed; // FIXME will be made obsolete by making flush() synchronous
484485
uint32_t mFlags;
485486
int mSessionId;
486487
int mAuxEffectId;

media/libmedia/AudioTrack.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ status_t AudioTrack::set(
259259
mMarkerReached = false;
260260
mNewPosition = 0;
261261
mUpdatePeriod = 0;
262+
mFlushed = false;
262263
mFlags = flags;
263264
AudioSystem::acquireAudioSessionId(mSessionId);
264265

@@ -337,6 +338,7 @@ void AudioTrack::start()
337338
audio_track_cblk_t* cblk = mCblk;
338339

339340
if (mActive == 0) {
341+
mFlushed = false;
340342
mActive = 1;
341343
mNewPosition = cblk->server + mUpdatePeriod;
342344
cblk->lock.lock();
@@ -437,6 +439,7 @@ void AudioTrack::flush_l()
437439
mUpdatePeriod = 0;
438440

439441
if (!mActive) {
442+
mFlushed = true;
440443
mAudioTrack->flush();
441444
// Release AudioTrack callback thread in case it was waiting for new buffers
442445
// in AudioTrack::obtainBuffer()
@@ -655,7 +658,7 @@ status_t AudioTrack::getPosition(uint32_t *position)
655658
{
656659
if (position == 0) return BAD_VALUE;
657660
AutoMutex lock(mLock);
658-
*position = mCblk->server;
661+
*position = mFlushed ? 0 : mCblk->server;
659662

660663
return NO_ERROR;
661664
}

0 commit comments

Comments
 (0)