Avoid deadlock in OMX::freeNode by making sure OMXCodecObserver does not hold the last reference of OMXCodec object
bug - 3336424 Change-Id: I4c79b66a900c527e3ae6a833f76d5da1b75c5a89
This commit is contained in:
@ -70,8 +70,6 @@ struct OMXCodec : public MediaSource,
|
||||
|
||||
virtual status_t pause();
|
||||
|
||||
void on_message(const omx_message &msg);
|
||||
|
||||
// from MediaBufferObserver
|
||||
virtual void signalBufferReturned(MediaBuffer *buffer);
|
||||
|
||||
@ -79,6 +77,13 @@ protected:
|
||||
virtual ~OMXCodec();
|
||||
|
||||
private:
|
||||
|
||||
// Make sure mLock is accessible to OMXCodecObserver
|
||||
friend class OMXCodecObserver;
|
||||
|
||||
// Call this with mLock hold
|
||||
void on_message(const omx_message &msg);
|
||||
|
||||
enum State {
|
||||
DEAD,
|
||||
LOADED,
|
||||
|
@ -235,7 +235,9 @@ struct OMXCodecObserver : public BnOMXObserver {
|
||||
sp<OMXCodec> codec = mTarget.promote();
|
||||
|
||||
if (codec.get() != NULL) {
|
||||
Mutex::Autolock autoLock(codec->mLock);
|
||||
codec->on_message(msg);
|
||||
codec.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1845,8 +1847,6 @@ OMXCodec::BufferInfo* OMXCodec::dequeueBufferFromNativeWindow() {
|
||||
}
|
||||
|
||||
void OMXCodec::on_message(const omx_message &msg) {
|
||||
Mutex::Autolock autoLock(mLock);
|
||||
|
||||
switch (msg.type) {
|
||||
case omx_message::EVENT:
|
||||
{
|
||||
|
@ -86,6 +86,9 @@ OMX::CallbackDispatcher::~CallbackDispatcher() {
|
||||
mQueueChanged.signal();
|
||||
}
|
||||
|
||||
// Don't call join on myself
|
||||
CHECK(mThread != pthread_self());
|
||||
|
||||
void *dummy;
|
||||
pthread_join(mThread, &dummy);
|
||||
}
|
||||
@ -246,9 +249,12 @@ status_t OMX::freeNode(node_id node) {
|
||||
|
||||
status_t err = instance->freeNode(mMaster);
|
||||
|
||||
index = mDispatchers.indexOfKey(node);
|
||||
CHECK(index >= 0);
|
||||
mDispatchers.removeItemsAt(index);
|
||||
{
|
||||
Mutex::Autolock autoLock(mLock);
|
||||
index = mDispatchers.indexOfKey(node);
|
||||
CHECK(index >= 0);
|
||||
mDispatchers.removeItemsAt(index);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
Reference in New Issue
Block a user