diff options
author | Wei Jia <wjia@google.com> | 2014-08-22 21:41:22 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-08-22 21:41:22 +0000 |
commit | 3672da6f03db75f7d7c86dd1e994e7758ba82670 (patch) | |
tree | 89e769697c928e8f1921f12542bf6feb540beb46 /media | |
parent | e61989593b2afec539f7d699e5b4c0bfdbca27d8 (diff) | |
parent | 7992a5d0f6d995d46bf649dbac45e0e8267f1397 (diff) | |
download | frameworks_av-3672da6f03db75f7d7c86dd1e994e7758ba82670.zip frameworks_av-3672da6f03db75f7d7c86dd1e994e7758ba82670.tar.gz frameworks_av-3672da6f03db75f7d7c86dd1e994e7758ba82670.tar.bz2 |
am 7992a5d0: Merge "NuPlayerDriver: fix current position for stop and pause." into lmp-dev
* commit '7992a5d0f6d995d46bf649dbac45e0e8267f1397':
NuPlayerDriver: fix current position for stop and pause.
Diffstat (limited to 'media')
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp | 59 | ||||
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerDriver.h | 2 |
2 files changed, 44 insertions, 17 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp index c0091bf..60beb9d 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp @@ -36,8 +36,8 @@ NuPlayerDriver::NuPlayerDriver() mAsyncResult(UNKNOWN_ERROR), mDurationUs(-1), mPositionUs(-1), - mNotifyTimeRealUs(0), - mPauseStartedTimeUs(0), + mNotifyTimeRealUs(-1), + mPauseStartedTimeUs(-1), mNumFramesTotal(0), mNumFramesDropped(0), mLooper(new ALooper), @@ -240,7 +240,14 @@ status_t NuPlayerDriver::start() { } case STATE_RUNNING: + { + if (mAtEOS) { + mPlayer->seekToAsync(0); + mAtEOS = false; + mPositionUs = -1; + } break; + } case STATE_PAUSED: case STATE_STOPPED_AND_PREPARED: @@ -255,6 +262,7 @@ status_t NuPlayerDriver::start() { } mState = STATE_RUNNING; + mPauseStartedTimeUs = -1; return OK; } @@ -268,7 +276,7 @@ status_t NuPlayerDriver::stop() { // fall through case STATE_PAUSED: - notifyListener(MEDIA_STOPPED); + notifyListener_l(MEDIA_STOPPED); // fall through case STATE_PREPARED: @@ -281,7 +289,7 @@ status_t NuPlayerDriver::stop() { default: return INVALID_OPERATION; } - mPauseStartedTimeUs = ALooper::GetNowUs(); + setPauseStartedTimeIfNeeded(); return OK; } @@ -295,7 +303,7 @@ status_t NuPlayerDriver::pause() { return OK; case STATE_RUNNING: - notifyListener(MEDIA_PAUSED); + notifyListener_l(MEDIA_PAUSED); mPlayer->pause(); break; @@ -303,7 +311,7 @@ status_t NuPlayerDriver::pause() { return INVALID_OPERATION; } - mPauseStartedTimeUs = ALooper::GetNowUs(); + setPauseStartedTimeIfNeeded(); mState = STATE_PAUSED; return OK; @@ -334,7 +342,7 @@ status_t NuPlayerDriver::seekTo(int msec) { { mAtEOS = false; // seeks can take a while, so we essentially paused - notifyListener(MEDIA_PAUSED); + notifyListener_l(MEDIA_PAUSED); mPlayer->seekToAsync(seekTimeUs); break; } @@ -343,6 +351,8 @@ status_t NuPlayerDriver::seekTo(int msec) { return INVALID_OPERATION; } + mPositionUs = seekTimeUs; + mNotifyTimeRealUs = -1; return OK; } @@ -351,10 +361,11 @@ status_t NuPlayerDriver::getCurrentPosition(int *msec) { if (mPositionUs < 0) { *msec = 0; + } else if (mNotifyTimeRealUs == -1) { + *msec = mPositionUs / 1000; } else { int64_t nowUs = - (mState != STATE_RUNNING ? - mPauseStartedTimeUs : ALooper::GetNowUs()); + (isPlaying() ? ALooper::GetNowUs() : mPauseStartedTimeUs); *msec = (mPositionUs + nowUs - mNotifyTimeRealUs + 500ll) / 1000; } @@ -388,7 +399,7 @@ status_t NuPlayerDriver::reset() { { CHECK(mIsAsyncPrepare); - notifyListener(MEDIA_PREPARED); + notifyListener_l(MEDIA_PREPARED); break; } @@ -397,7 +408,7 @@ status_t NuPlayerDriver::reset() { } if (mState != STATE_STOPPED) { - notifyListener(MEDIA_STOPPED); + notifyListener_l(MEDIA_STOPPED); } mState = STATE_RESET_IN_PROGRESS; @@ -552,10 +563,7 @@ void NuPlayerDriver::notifySeekComplete_l() { // no need to notify listener return; } - // note: notifyListener called with lock released - mLock.unlock(); - notifyListener(wasSeeking ? MEDIA_SEEK_COMPLETE : MEDIA_PREPARED); - mLock.lock(); + notifyListener_l(wasSeeking ? MEDIA_SEEK_COMPLETE : MEDIA_PREPARED); } void NuPlayerDriver::notifyFrameStats( @@ -587,11 +595,19 @@ status_t NuPlayerDriver::dump( void NuPlayerDriver::notifyListener( int msg, int ext1, int ext2, const Parcel *in) { + Mutex::Autolock autoLock(mLock); + notifyListener_l(msg, ext1, ext2, in); +} + +void NuPlayerDriver::notifyListener_l( + int msg, int ext1, int ext2, const Parcel *in) { switch (msg) { case MEDIA_PLAYBACK_COMPLETE: { if (mLooping) { + mLock.unlock(); mPlayer->seekToAsync(0); + mLock.lock(); break; } // fall through @@ -600,6 +616,7 @@ void NuPlayerDriver::notifyListener( case MEDIA_ERROR: { mAtEOS = true; + setPauseStartedTimeIfNeeded(); break; } @@ -607,7 +624,9 @@ void NuPlayerDriver::notifyListener( break; } + mLock.unlock(); sendEvent(msg, ext1, ext2, in); + mLock.lock(); } void NuPlayerDriver::notifySetDataSourceCompleted(status_t err) { @@ -637,12 +656,12 @@ void NuPlayerDriver::notifyPrepareCompleted(status_t err) { if (err == OK) { if (mIsAsyncPrepare) { - notifyListener(MEDIA_PREPARED); + notifyListener_l(MEDIA_PREPARED); } mState = STATE_PREPARED; } else { if (mIsAsyncPrepare) { - notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err); + notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err); } mState = STATE_UNPREPARED; } @@ -656,4 +675,10 @@ void NuPlayerDriver::notifyFlagsChanged(uint32_t flags) { mPlayerFlags = flags; } +void NuPlayerDriver::setPauseStartedTimeIfNeeded() { + if (mPauseStartedTimeUs == -1) { + mPauseStartedTimeUs = ALooper::GetNowUs(); + } +} + } // namespace android diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h index 076493d..b0a52ad 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h @@ -120,6 +120,8 @@ private: int64_t mStartupSeekTimeUs; status_t prepare_l(); + void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL); + void setPauseStartedTimeIfNeeded(); DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver); }; |