ref: e014b5ea43af7ba16cbde79b8a11be65b2b66f0c
parent: 545612e4d7501564d92c979cf78e0f58ebed3597
author: Hank Peng <hankpeng@cisco.com>
date: Thu Nov 12 06:33:04 EST 2015
Avoid to call any host API after Encoding/DecodingComplete(), to avoid potential crash in the browser
--- a/module/gmp-openh264.cpp
+++ b/module/gmp-openh264.cpp
@@ -361,7 +361,8 @@
}
virtual void EncodingComplete() {
- // Release the reference to the callback, because it is no longer safe to call it
+ // Release the reference to the external objects, because it is no longer safe to call them
+ host_ = nullptr;
callback_ = nullptr;
Release();
}
@@ -481,12 +482,18 @@
void Encode_m (GMPVideoi420Frame* frame, SFrameBSInfo* encoded,
GMPVideoFrameType frame_type) {
+ // Attach a self-destructor so that this dies on return.
+ SelfDestruct<GMPVideoi420Frame> ifd (frame);
+
+ if (!host_) {
+ return;
+ }
+
// Now return the encoded data back to the parent.
GMPVideoFrame* ftmp;
GMPErr err = host_->CreateFrame (kGMPEncodedVideoFrame, &ftmp);
if (err != GMPNoErr) {
GMPLOG (GL_ERROR, "Error creating encoded frame");
- frame->Destroy();
return;
}
@@ -513,7 +520,6 @@
if (err != GMPNoErr) {
GMPLOG (GL_ERROR, "Error allocating frame data");
f->Destroy();
- frame->Destroy();
return;
}
@@ -539,9 +545,6 @@
<< " timestamp="
<< f->TimeStamp());
- // Destroy the frame.
- frame->Destroy();
-
// Return the encoded frame.
GMPCodecSpecificInfo info;
memset (&info, 0, sizeof (info)); // shouldn't be needed, we init everything
@@ -735,7 +738,8 @@
}
virtual void DecodingComplete() {
- // Release the reference to the callback, because it is no longer safe to call it
+ // Release the reference to the external objects, because it is no longer safe to call them
+ host_ = nullptr;
callback_ = nullptr;
Release();
}
@@ -836,6 +840,10 @@
GMPVideoFrame* ftmp = nullptr;
+ if (!host_) {
+ return;
+ }
+
// Translate the image.
GMPErr err = host_->CreateFrame (kGMPI420VideoFrame, &ftmp);
if (err != GMPNoErr) {