Allow AudioTrack to start at nonzero position
When creating a new AudioTrack (not inheriting one from a previous play),
the AudioSink should take the AudioTrack's position as the initial starting
point for mBytesWritten, since otherwise NuPlayer's calculations will be off.
Normally this position will be 0, but if the test code for 32 bit wraparound
in AudioFlinger.cpp is enabled, it might be (much) larger.
Change-Id: I1e4f906d529861c3dea996de8afc6dbd491589af
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 7c3fb0d..8bde8f1 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -1617,6 +1617,10 @@
mSampleRateHz = sampleRate;
mMsecsPerFrame = mPlaybackRatePermille / (float) sampleRate;
+ uint32_t pos;
+ if (t->getPosition(&pos) == OK) {
+ mBytesWritten = uint64_t(pos) * t->frameSize();
+ }
mTrack = t;
status_t res = t->setSampleRate(mPlaybackRatePermille * mSampleRateHz / 1000);