From 9e2b7918eb5621b24bd54c922f630da45339de77 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Mon, 18 Aug 2014 16:13:03 -0700 Subject: [PATCH] handle error during flush in MediaPlayer.reset() If there was an error during the flush phase of a reset, then the reset would never complete. We now make sure the MediaCodec moves to the right state in this case, and that NuPlayer cleans up and resumes the rest of the reset after a failed flush. Bug: 16955082 Change-Id: Ied61136871a9fcdffcc80647fa2bba64a926ac2a --- media/libmediaplayerservice/nuplayer/NuPlayer.cpp | 8 ++++++++ media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp | 4 ++-- media/libstagefright/MediaCodec.cpp | 11 ++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index 5e7ecfae5a..818155c314 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -782,6 +782,14 @@ void NuPlayer::onMessageReceived(const sp &msg) { err = UNKNOWN_ERROR; } mRenderer->queueEOS(audio, err); + if (audio && mFlushingAudio != NONE) { + mAudioDecoder.clear(); + mFlushingAudio = SHUT_DOWN; + } else if (!audio && mFlushingVideo != NONE){ + mVideoDecoder.clear(); + mFlushingVideo = SHUT_DOWN; + } + finishFlushIfPossible(); } else if (what == Decoder::kWhatDrainThisBuffer) { renderBuffer(audio, msg); } else { diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp index 8fce2f426e..60c645a419 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp @@ -44,11 +44,11 @@ NuPlayer::Decoder::Decoder( // Every decoder has its own looper because MediaCodec operations // are blocking, but NuPlayer needs asynchronous operations. mDecoderLooper = new ALooper; - mDecoderLooper->setName("NuPlayerDecoder"); + mDecoderLooper->setName("NPDecoder"); mDecoderLooper->start(false, false, ANDROID_PRIORITY_AUDIO); mCodecLooper = new ALooper; - mCodecLooper->setName("NuPlayerDecoder-MC"); + mCodecLooper->setName("NPDecoder-CL"); mCodecLooper->start(false, false, ANDROID_PRIORITY_AUDIO); } diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index 42691b9575..1181c2bc73 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -716,7 +716,8 @@ void MediaCodec::onMessageReceived(const sp &msg) { CHECK(msg->findInt32("err", &err)); CHECK(msg->findInt32("actionCode", &actionCode)); - ALOGE("Codec reported err %#x, actionCode %d", err, actionCode); + ALOGE("Codec reported err %#x, actionCode %d, while in state %d", + err, actionCode, mState); if (err == DEAD_OBJECT) { mFlags |= kFlagSawMediaServerDie; } @@ -767,8 +768,12 @@ void MediaCodec::onMessageReceived(const sp &msg) { case FLUSHING: { - setState( - (mFlags & kFlagIsAsync) ? FLUSHED : STARTED); + if (actionCode == ACTION_CODE_FATAL) { + setState(UNINITIALIZED); + } else { + setState( + (mFlags & kFlagIsAsync) ? FLUSHED : STARTED); + } break; } -- 2.11.0