summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2013-09-26 17:23:10 -0700
committerEric Laurent <elaurent@google.com>2013-09-27 09:22:22 -0700
commit91b0ca1a5bea44dd9b5196910186dd2927821994 (patch)
treee767acc4afa236de4c62db0383a9440baea8d539 /media
parent0adc67dfc5cedb211c36f06849681a60a32f5805 (diff)
downloadframeworks_av-91b0ca1a5bea44dd9b5196910186dd2927821994.zip
frameworks_av-91b0ca1a5bea44dd9b5196910186dd2927821994.tar.gz
frameworks_av-91b0ca1a5bea44dd9b5196910186dd2927821994.tar.bz2
fix playback position after switching to offload
After switching from offloaded track to PCM track while paused (e.g. when connecting A2DP), playback restarts from the beginning of the song when resuming. Save current position before recreating an AudioPlayer in AwesomePlayer::play_l() and seek to the saved position before starting playback. Also fix a problem where the position is not reported properly by AudioPlayer if a seek is pending and queried just after start and before the first buffer is read from the MediaSource. Bug: 8174034. Change-Id: I254e65418ff903a9bf2e2111b89a00e2e54876c5
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/AudioPlayer.cpp34
-rw-r--r--media/libstagefright/AwesomePlayer.cpp7
2 files changed, 28 insertions, 13 deletions
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp
index e38e261..a8a8786 100644
--- a/media/libstagefright/AudioPlayer.cpp
+++ b/media/libstagefright/AudioPlayer.cpp
@@ -363,6 +363,7 @@ void AudioPlayer::reset() {
mPositionTimeMediaUs = -1;
mPositionTimeRealUs = -1;
mSeeking = false;
+ mSeekTimeUs = 0;
mReachedEOS = false;
mFinalStatus = OK;
mStarted = false;
@@ -602,15 +603,24 @@ size_t AudioPlayer::fillBuffer(void *data, size_t size) {
// need to adjust the mStartPosUs for offload decoding since parser
// might not be able to get the exact seek time requested.
- if (refreshSeekTime && useOffload()) {
- if (postSeekComplete) {
- ALOGV("fillBuffer is going to post SEEK_COMPLETE");
- mObserver->postAudioSeekComplete();
- postSeekComplete = false;
- }
+ if (refreshSeekTime) {
+ if (useOffload()) {
+ if (postSeekComplete) {
+ ALOGV("fillBuffer is going to post SEEK_COMPLETE");
+ mObserver->postAudioSeekComplete();
+ postSeekComplete = false;
+ }
- mStartPosUs = mPositionTimeMediaUs;
- ALOGV("adjust seek time to: %.2f", mStartPosUs/ 1E6);
+ mStartPosUs = mPositionTimeMediaUs;
+ ALOGV("adjust seek time to: %.2f", mStartPosUs/ 1E6);
+ }
+ // clear seek time with mLock locked and once we have valid mPositionTimeMediaUs
+ // and mPositionTimeRealUs
+ // before clearing mSeekTimeUs check if a new seek request has been received while
+ // we were reading from the source with mLock released.
+ if (!mSeeking) {
+ mSeekTimeUs = 0;
+ }
}
if (!useOffload()) {
@@ -741,12 +751,10 @@ int64_t AudioPlayer::getMediaTimeUs() {
return mPositionTimeRealUs;
}
- if (mPositionTimeMediaUs < 0 || mPositionTimeRealUs < 0) {
- if (mSeeking) {
- return mSeekTimeUs;
- }
- return 0;
+ if (mPositionTimeMediaUs < 0 || mPositionTimeRealUs < 0) {
+ // mSeekTimeUs is either seek time while seeking or 0 if playback did not start.
+ return mSeekTimeUs;
}
int64_t realTimeOffset = getRealTimeUsLocked() - mPositionTimeRealUs;
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 5fbee7e..9b0c69a 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -927,6 +927,9 @@ status_t AwesomePlayer::play_l() {
if ((err != OK) && mOffloadAudio) {
ALOGI("play_l() cannot create offload output, fallback to sw decode");
+ int64_t curTimeUs;
+ getPosition(&curTimeUs);
+
delete mAudioPlayer;
mAudioPlayer = NULL;
// if the player was started it will take care of stopping the source when destroyed
@@ -942,6 +945,10 @@ status_t AwesomePlayer::play_l() {
if (err != OK) {
mAudioSource.clear();
} else {
+ mSeekNotificationSent = true;
+ if (mExtractorFlags & MediaExtractor::CAN_SEEK) {
+ seekTo_l(curTimeUs);
+ }
createAudioPlayer_l();
err = startAudioPlayer_l(false);
}