diff options
| author | 2010-07-07 13:35:27 -0700 | |
|---|---|---|
| committer | 2010-07-07 13:36:29 -0700 | |
| commit | 971305d4af1c4058596c5a3feac301585682d15c (patch) | |
| tree | 40b2af7b6efaf44088871ed8d7600bd966bacab5 | |
| parent | b59b94456b3a8fdfdf524a81274839f657fbb65b (diff) | |
Only send the playback complete notification if a) an error occurred on any track or b) all tracks have finished playing. The previous behaviour was to send the notification as soon as the first track finished playing.
Change-Id: Icac8104d14f18b719aa0b8f1ab3215f24003b152
| -rw-r--r-- | media/libstagefright/AwesomePlayer.cpp | 52 | ||||
| -rw-r--r-- | media/libstagefright/include/AwesomePlayer.h | 5 |
2 files changed, 37 insertions, 20 deletions
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index 4a1580f5f977..ffed74f1b064 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -371,9 +371,6 @@ void AwesomePlayer::reset_l() { } mAudioSource.clear(); - if (mTimeSource != mAudioPlayer) { - delete mTimeSource; - } mTimeSource = NULL; delete mAudioPlayer; @@ -494,22 +491,35 @@ void AwesomePlayer::onStreamDone() { } mStreamDoneEventPending = false; - if (mStreamDoneStatus == ERROR_END_OF_STREAM && (mFlags & LOOPING)) { + if (mStreamDoneStatus != ERROR_END_OF_STREAM) { + LOGV("MEDIA_ERROR %d", mStreamDoneStatus); + + notifyListener_l( + MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, mStreamDoneStatus); + + pause_l(); + + mFlags |= AT_EOS; + return; + } + + const bool allDone = + (mVideoSource == NULL || (mFlags & VIDEO_AT_EOS)) + && (mAudioSource == NULL || (mFlags & AUDIO_AT_EOS)); + + if (!allDone) { + return; + } + + if (mFlags & LOOPING) { seekTo_l(0); if (mVideoSource != NULL) { postVideoEvent_l(); } } else { - if (mStreamDoneStatus == ERROR_END_OF_STREAM) { - LOGV("MEDIA_PLAYBACK_COMPLETE"); - notifyListener_l(MEDIA_PLAYBACK_COMPLETE); - } else { - LOGV("MEDIA_ERROR %d", mStreamDoneStatus); - - notifyListener_l( - MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, mStreamDoneStatus); - } + LOGV("MEDIA_PLAYBACK_COMPLETE"); + notifyListener_l(MEDIA_PLAYBACK_COMPLETE); pause_l(); @@ -563,7 +573,6 @@ status_t AwesomePlayer::play_l() { return err; } - delete mTimeSource; mTimeSource = mAudioPlayer; deferredAudioSeek = true; @@ -579,7 +588,7 @@ status_t AwesomePlayer::play_l() { } if (mTimeSource == NULL && mAudioPlayer == NULL) { - mTimeSource = new SystemTimeSource; + mTimeSource = &mSystemTimeSource; } if (mVideoSource != NULL) { @@ -744,7 +753,7 @@ status_t AwesomePlayer::seekTo_l(int64_t timeUs) { mSeeking = true; mSeekNotificationSent = false; mSeekTimeUs = timeUs; - mFlags &= ~AT_EOS; + mFlags &= ~(AT_EOS | AUDIO_AT_EOS | VIDEO_AT_EOS); seekAudioIfNecessary_l(); @@ -924,6 +933,7 @@ void AwesomePlayer::onVideoEvent() { continue; } + mFlags |= VIDEO_AT_EOS; postStreamDoneEvent_l(err); return; } @@ -968,19 +978,21 @@ void AwesomePlayer::onVideoEvent() { mSeekNotificationSent = false; } + TimeSource *ts = (mFlags & AUDIO_AT_EOS) ? &mSystemTimeSource : mTimeSource; + if (mFlags & FIRST_FRAME) { mFlags &= ~FIRST_FRAME; - mTimeSourceDeltaUs = mTimeSource->getRealTimeUs() - timeUs; + mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs; } int64_t realTimeUs, mediaTimeUs; - if (mAudioPlayer != NULL + if (!(mFlags & AUDIO_AT_EOS) && mAudioPlayer != NULL && mAudioPlayer->getMediaTimeMapping(&realTimeUs, &mediaTimeUs)) { mTimeSourceDeltaUs = realTimeUs - mediaTimeUs; } - int64_t nowUs = mTimeSource->getRealTimeUs() - mTimeSourceDeltaUs; + int64_t nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs; int64_t latenessUs = nowUs - timeUs; @@ -1081,6 +1093,8 @@ void AwesomePlayer::onCheckAudioStatus() { status_t finalStatus; if (mWatchForAudioEOS && mAudioPlayer->reachedEOS(&finalStatus)) { mWatchForAudioEOS = false; + mFlags |= AUDIO_AT_EOS; + mFlags |= FIRST_FRAME; postStreamDoneEvent_l(finalStatus); } diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h index 2a9f21b4b3b0..8d0877cbdd93 100644 --- a/media/libstagefright/include/AwesomePlayer.h +++ b/media/libstagefright/include/AwesomePlayer.h @@ -24,6 +24,7 @@ #include <media/MediaPlayerInterface.h> #include <media/stagefright/DataSource.h> #include <media/stagefright/OMXClient.h> +#include <media/stagefright/TimeSource.h> #include <utils/threads.h> namespace android { @@ -33,7 +34,6 @@ struct DataSource; struct MediaBuffer; struct MediaExtractor; struct MediaSource; -struct TimeSource; struct NuCachedSource2; struct ALooper; @@ -102,6 +102,8 @@ private: AT_EOS = 32, PREPARE_CANCELLED = 64, CACHE_UNDERRUN = 128, + AUDIO_AT_EOS = 256, + VIDEO_AT_EOS = 512, }; mutable Mutex mLock; @@ -115,6 +117,7 @@ private: sp<ISurface> mISurface; sp<MediaPlayerBase::AudioSink> mAudioSink; + SystemTimeSource mSystemTimeSource; TimeSource *mTimeSource; String8 mUri; |