Bug 1047442: Add thread to resolve deadlock on sendCritSect caused by sync Encode dispatch to GMPThread r=pkerr

This commit is contained in:
Randell Jesup 2014-08-01 17:27:52 -04:00
Родитель acbb3b1f28
Коммит 00588c59cc
3 изменённых файлов: 28 добавлений и 6 удалений

Просмотреть файл

@ -62,10 +62,16 @@ GMPVideoEncoderParent::GMPVideoEncoderParent(GMPParent *aPlugin)
mVideoHost(MOZ_THIS_IN_INITIALIZER_LIST())
{
MOZ_ASSERT(mPlugin);
nsresult rv = NS_NewNamedThread("GMPEncoded", getter_AddRefs(mEncodedThread));
if (NS_FAILED(rv)) {
MOZ_CRASH();
}
}
GMPVideoEncoderParent::~GMPVideoEncoderParent()
{
mEncodedThread->Shutdown();
}
GMPVideoHostImpl&
@ -250,6 +256,21 @@ GMPVideoEncoderParent::ActorDestroy(ActorDestroyReason aWhy)
mVideoHost.ActorDestroyed();
}
static void
EncodedCallback(GMPVideoEncoderCallbackProxy* aCallback,
GMPVideoEncodedFrame* aEncodedFrame,
nsTArray<uint8_t>* aCodecSpecificInfo,
nsCOMPtr<nsIThread> aThread)
{
aCallback->Encoded(aEncodedFrame, *aCodecSpecificInfo);
delete aCodecSpecificInfo;
// Ugh. Must destroy the frame on GMPThread.
// XXX add locks to the ShmemManager instead?
aThread->Dispatch(WrapRunnable(aEncodedFrame,
&GMPVideoEncodedFrame::Destroy),
NS_DISPATCH_NORMAL);
}
bool
GMPVideoEncoderParent::RecvEncoded(const GMPVideoEncodedFrameData& aEncodedFrame,
const nsTArray<uint8_t>& aCodecSpecificInfo)
@ -259,12 +280,14 @@ GMPVideoEncoderParent::RecvEncoded(const GMPVideoEncodedFrameData& aEncodedFrame
}
auto f = new GMPVideoEncodedFrameImpl(aEncodedFrame, &mVideoHost);
nsTArray<uint8_t> *codecSpecificInfo = new nsTArray<uint8_t>;
codecSpecificInfo->AppendElements((uint8_t*)aCodecSpecificInfo.Elements(), aCodecSpecificInfo.Length());
nsCOMPtr<nsIThread> thread = NS_GetCurrentThread();
// Ignore any return code. It is OK for this to fail without killing the process.
mCallback->Encoded(f, aCodecSpecificInfo);
mEncodedThread->Dispatch(WrapRunnableNM(&EncodedCallback,
mCallback, f, codecSpecificInfo, thread),
NS_DISPATCH_NORMAL);
// Return SHM to sender to recycle
//SendEncodedReturn(aEncodedFrame, aCodecSpecificInfo);
return true;
}

Просмотреть файл

@ -77,6 +77,7 @@ private:
nsRefPtr<GMPParent> mPlugin;
GMPVideoEncoderCallbackProxy* mCallback;
GMPVideoHostImpl mVideoHost;
nsCOMPtr<nsIThread> mEncodedThread;
};
} // namespace gmp

Просмотреть файл

@ -420,7 +420,6 @@ WebrtcGmpVideoEncoder::Encoded(GMPVideoEncodedFrame* aEncodedFrame,
default:
// really that it's not in the enum; gives more readable error
MOZ_ASSERT(aEncodedFrame->BufferType() != GMP_BufferSingle);
aEncodedFrame->Destroy();
return;
}
webrtc::EncodedImage unit(buffer, size, size);
@ -433,7 +432,6 @@ WebrtcGmpVideoEncoder::Encoded(GMPVideoEncodedFrame* aEncodedFrame,
buffer += size;
}
}
aEncodedFrame->Destroy();
}
// Decoder.