From 6610a7d621c634fe059b855ca7eb3f58fb8d0757 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 11 Apr 2013 16:06:14 -0700 Subject: ACodec now signals an error if the mediaserver died while it is in anything other than "uninitialized" state. Change-Id: Id133d897ac65b455b34e5de17ff9c39b47285630 related-to-bug: 8397711 --- media/libstagefright/ACodec.cpp | 57 ++++++++++++++++++++++++++++++++------ media/libstagefright/OMXClient.cpp | 2 +- 2 files changed, 50 insertions(+), 9 deletions(-) (limited to 'media') diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index ff72b71..01ff07e 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -166,6 +166,24 @@ private: //////////////////////////////////////////////////////////////////////////////// +struct ACodec::DeathNotifier : public IBinder::DeathRecipient { + DeathNotifier(const sp ¬ify) + : mNotify(notify) { + } + + virtual void binderDied(const wp &) { + mNotify->post(); + } + +protected: + virtual ~DeathNotifier() {} + +private: + sp mNotify; + + DISALLOW_EVIL_CONSTRUCTORS(DeathNotifier); +}; + struct ACodec::UninitializedState : public ACodec::BaseState { UninitializedState(ACodec *codec); @@ -177,6 +195,8 @@ private: void onSetup(const sp &msg); bool onAllocateComponent(const sp &msg); + sp mDeathNotifier; + DISALLOW_EVIL_CONSTRUCTORS(UninitializedState); }; @@ -2487,6 +2507,13 @@ bool ACodec::BaseState::onMessageReceived(const sp &msg) { return true; } + case ACodec::kWhatOMXDied: + { + ALOGE("OMX/mediaserver died, signalling error!"); + mCodec->signalError(OMX_ErrorResourcesLost, DEAD_OBJECT); + break; + } + default: return false; } @@ -3035,6 +3062,18 @@ ACodec::UninitializedState::UninitializedState(ACodec *codec) void ACodec::UninitializedState::stateEntered() { ALOGV("Now uninitialized"); + + if (mDeathNotifier != NULL) { + mCodec->mOMX->asBinder()->unlinkToDeath(mDeathNotifier); + mDeathNotifier.clear(); + } + + mCodec->mNativeWindow.clear(); + mCodec->mNode = NULL; + mCodec->mOMX.clear(); + mCodec->mQuirks = 0; + mCodec->mFlags = 0; + mCodec->mComponentName.clear(); } bool ACodec::UninitializedState::onMessageReceived(const sp &msg) { @@ -3106,6 +3145,15 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp &msg) { sp omx = client.interface(); + sp notify = new AMessage(kWhatOMXDied, mCodec->id()); + + mDeathNotifier = new DeathNotifier(notify); + if (omx->asBinder()->linkToDeath(mDeathNotifier) != OK) { + // This was a local binder, if it dies so do we, we won't care + // about any notifications in the afterlife. + mDeathNotifier.clear(); + } + Vector matchingCodecs; AString mime; @@ -3170,7 +3218,7 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp &msg) { return false; } - sp notify = new AMessage(kWhatOMXMessage, mCodec->id()); + notify = new AMessage(kWhatOMXMessage, mCodec->id()); observer->setNotificationMessage(notify); mCodec->mComponentName = componentName; @@ -3224,13 +3272,6 @@ void ACodec::LoadedState::onShutdown(bool keepComponentAllocated) { if (!keepComponentAllocated) { CHECK_EQ(mCodec->mOMX->freeNode(mCodec->mNode), (status_t)OK); - mCodec->mNativeWindow.clear(); - mCodec->mNode = NULL; - mCodec->mOMX.clear(); - mCodec->mQuirks = 0; - mCodec->mFlags = 0; - mCodec->mComponentName.clear(); - mCodec->changeState(mCodec->mUninitializedState); } diff --git a/media/libstagefright/OMXClient.cpp b/media/libstagefright/OMXClient.cpp index ff72e0e..1822f07 100644 --- a/media/libstagefright/OMXClient.cpp +++ b/media/libstagefright/OMXClient.cpp @@ -32,7 +32,7 @@ struct MuxOMX : public IOMX { MuxOMX(const sp &remoteOMX); virtual ~MuxOMX(); - virtual IBinder *onAsBinder() { return NULL; } + virtual IBinder *onAsBinder() { return mRemoteOMX->asBinder().get(); } virtual bool livesLocally(node_id node, pid_t pid); -- cgit v1.1