зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1599799
- p2: discard frame when callback is invalid. r=jya
Client of WebrtcMediaDataEncoder unregisters callback before calling Shutdown(). When a pending encode promise gets resolved after that, it will cause null pointer error. Differential Revision: https://phabricator.services.mozilla.com/D55760 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8f7d3c7b5b
Коммит
28491d1c76
|
@ -157,17 +157,25 @@ bool WebrtcMediaDataEncoder::InitEncoder() {
|
|||
|
||||
int32_t WebrtcMediaDataEncoder::RegisterEncodeCompleteCallback(
|
||||
webrtc::EncodedImageCallback* aCallback) {
|
||||
mCallback = aCallback;
|
||||
OwnerThread()->Dispatch(NS_NewRunnableFunction(
|
||||
"WebrtcMediaDataEncoder::RegisterEncodeCompleteCallback",
|
||||
[self = RefPtr<WebrtcMediaDataEncoder>(this), aCallback]() {
|
||||
self->mCallback = aCallback;
|
||||
}));
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
int32_t WebrtcMediaDataEncoder::Shutdown() {
|
||||
LOG("Release encoder");
|
||||
auto rv = media::Await(do_AddRef(mThreadPool), mEncoder->Shutdown());
|
||||
mEncoder = nullptr;
|
||||
mCallback = nullptr;
|
||||
mError = NS_OK;
|
||||
return rv.IsResolve() ? WEBRTC_VIDEO_CODEC_OK : WEBRTC_VIDEO_CODEC_ERROR;
|
||||
OwnerThread()->Dispatch(NS_NewRunnableFunction(
|
||||
"WebrtcMediaDataEncoder::Shutdown",
|
||||
[self = RefPtr<WebrtcMediaDataEncoder>(this),
|
||||
encoder = RefPtr<MediaDataEncoder>(mEncoder.forget())]() {
|
||||
self->mCallback = nullptr;
|
||||
self->mError = NS_OK;
|
||||
encoder->Shutdown();
|
||||
}));
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
RefPtr<MediaData> WebrtcMediaDataEncoder::CreateVideoDataFromWebrtcVideoFrame(
|
||||
|
@ -242,6 +250,10 @@ void WebrtcMediaDataEncoder::ProcessEncode(
|
|||
[display, self = RefPtr<WebrtcMediaDataEncoder>(this),
|
||||
// capture this for printing address in LOG.
|
||||
this](const MediaDataEncoder::EncodedData& aData) {
|
||||
// Callback has been unregistered.
|
||||
if (!mCallback) {
|
||||
return;
|
||||
}
|
||||
// The encoder haven't finished encoding yet.
|
||||
if (aData.IsEmpty()) {
|
||||
return;
|
||||
|
|
Загрузка…
Ссылка в новой задаче