ref: 24916a652ee5d3e36d931c222df20966f7c158fa
parent: 643df65c585b87a980679fe4a3f1a30732c3feca
parent: b5f1460dd1be3ee23468daf8b46724e1f1dc0126
author: huili2 <huili2@cisco.com>
date: Tue Nov 10 04:07:41 EST 2015
Merge pull request #2215 from pengyanhai/master Tear down the OpenH264 encoder and decoder properly to avoid potential crash and memory leak
--- a/module/gmp-openh264.cpp
+++ b/module/gmp-openh264.cpp
@@ -368,9 +368,24 @@
private:
virtual ~OpenH264VideoEncoder() {
- worker_thread_->Join();
+ // Tear down the internal encoder
+ TearDownEncoder();
}
+ void TearDownEncoder() {
+ // Stop the worker thread first
+ if (worker_thread_) {
+ worker_thread_->Join();
+ worker_thread_ = nullptr;
+ }
+
+ // Destroy OpenH264 encoder
+ if (encoder_) {
+ WelsDestroySVCEncoder(encoder_);
+ encoder_ = nullptr;
+ }
+ }
+
void Error (GMPErr error) {
if (callback_) {
callback_->Error (error);
@@ -727,8 +742,23 @@
private:
virtual ~OpenH264VideoDecoder() {
+ // Tear down the internal decoder
+ TearDownDecoder();
}
+ void TearDownDecoder() {
+ // Stop the worker thread first
+ if (worker_thread_) {
+ worker_thread_->Join();
+ worker_thread_ = nullptr;
+ }
+
+ // Destroy OpenH264 decoder
+ if (decoder_) {
+ WelsDestroyDecoder(decoder_);
+ decoder_ = nullptr;
+ }
+ }
void Error (GMPErr error) {
if (callback_) {
callback_->Error (error);