From 42c5ae81036d4002da3fe1e3b1016131ba737e74 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Fri, 27 Sep 2013 12:13:52 -0700 Subject: Prevent onPrepared callback from being called twice b/10891995 Change-Id: If6845c832d114629282f0b03f904a37c3325208e --- media/libstagefright/AwesomePlayer.cpp | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'media/libstagefright/AwesomePlayer.cpp') diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index 5fbee7e..bcf9cd3 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -259,6 +259,7 @@ void AwesomePlayer::cancelPlayerEvents(bool keepNotifications) { mQueue.cancelEvent(mBufferingEvent->eventID()); mBufferingEventPending = false; + mAudioTearDown = false; } } @@ -2301,6 +2302,7 @@ void AwesomePlayer::abortPrepare(status_t err) { modifyFlags((PREPARING|PREPARE_CANCELLED|PREPARING_CONNECTED), CLEAR); mAsyncPrepareEvent = NULL; mPreparedCondition.broadcast(); + mAudioTearDown = false; } // static @@ -2374,6 +2376,20 @@ void AwesomePlayer::finishAsyncPrepare_l() { modifyFlags(PREPARED, SET); mAsyncPrepareEvent = NULL; mPreparedCondition.broadcast(); + + if (mAudioTearDown) { + if (mPrepareResult == OK) { + if (mExtractorFlags & MediaExtractor::CAN_SEEK) { + seekTo_l(mAudioTearDownPosition); + } + + if (mAudioTearDownWasPlaying) { + modifyFlags(CACHE_UNDERRUN, CLEAR); + play_l(); + } + } + mAudioTearDown = false; + } } uint32_t AwesomePlayer::flags() const { @@ -2791,7 +2807,7 @@ void AwesomePlayer::onAudioTearDownEvent() { ALOGV("onAudioTearDownEvent"); // stream info is cleared by reset_l() so copy what we need - const bool wasPlaying = (mFlags & PLAYING); + mAudioTearDownWasPlaying = (mFlags & PLAYING); KeyedVector uriHeaders(mUriHeaders); sp fileSource(mFileSource); @@ -2800,8 +2816,7 @@ void AwesomePlayer::onAudioTearDownEvent() { mStatsLock.unlock(); // get current position so we can start recreated stream from here - int64_t position = 0; - getPosition(&position); + getPosition(&mAudioTearDownPosition); // Reset and recreate reset_l(); @@ -2825,21 +2840,8 @@ void AwesomePlayer::onAudioTearDownEvent() { mAudioTearDown = true; mIsAsyncPrepare = true; - // Call parepare for the host decoding + // Call prepare for the host decoding beginPrepareAsync_l(); - - if (mPrepareResult == OK) { - if (mExtractorFlags & MediaExtractor::CAN_SEEK) { - seekTo_l(position); - } - - if (wasPlaying) { - modifyFlags(CACHE_UNDERRUN, CLEAR); - play_l(); - } - } - - mAudioTearDown = false; } } // namespace android -- cgit v1.1