summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-07-07 13:35:27 -0700
committerAndreas Huber <andih@google.com>2010-07-07 13:36:29 -0700
commit5d2de4da54504836e4b772b3010ac28c19f667f0 (patch)
treed0b5024ea62969e5b1490f820bfc2faadd9c08ae /media
parent91952e5221d2151e10738d7228575c4afe444f5e (diff)
downloadframeworks_av-5d2de4da54504836e4b772b3010ac28c19f667f0.zip
frameworks_av-5d2de4da54504836e4b772b3010ac28c19f667f0.tar.gz
frameworks_av-5d2de4da54504836e4b772b3010ac28c19f667f0.tar.bz2
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
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/AwesomePlayer.cpp52
-rw-r--r--media/libstagefright/include/AwesomePlayer.h5
2 files changed, 37 insertions, 20 deletions
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 4a1580f..ffed74f 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 2a9f21b..8d0877c 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;