shithub: openh264

Download patch

ref: 408b7cad17e657718ada77b7270fc6147ada69b6
parent: 8b1206001c27db9828a659f07963154d74cbc41c
author: sijchen <sijchen@cisco.com>
date: Wed Feb 10 05:42:45 EST 2016

use WelsUninitEncoderExt rather than FreeMemorySvc which correctly deals with release of vpp memory

--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2434,6 +2434,51 @@
 }
 
 /*!
+ * \brief   uninitialize Wels encoder core library
+ * \pParam  pEncCtx     sWelsEncCtx*
+ * \return  none
+ */
+void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) {
+  if (NULL == ppCtx || NULL == *ppCtx)
+    return;
+
+  WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+           "WelsUninitEncoderExt(), pCtx= %p, iMultipleThreadIdc= %d.",
+           (void*) (*ppCtx), (*ppCtx)->pSvcParam->iMultipleThreadIdc);
+
+#if defined(STAT_OUTPUT)
+  StatOverallEncodingExt (*ppCtx);
+#endif
+
+  if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) {
+    const int32_t iThreadCount = (*ppCtx)->pSvcParam->iMultipleThreadIdc;
+    int32_t iThreadIdx = 0;
+
+    while (iThreadIdx < iThreadCount) {
+      int res = 0;
+      if ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]) {
+        WelsEventSignal (& (*ppCtx)->pSliceThreading->pExitEncodeEvent[iThreadIdx]);
+        WelsEventSignal (& (*ppCtx)->pSliceThreading->pThreadMasterEvent[iThreadIdx]);
+        res = WelsThreadJoin ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]); // waiting thread exit
+        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO, "WelsUninitEncoderExt(), pthread_join(pThreadHandles%d) return %d..",
+                 iThreadIdx,
+                 res);
+        (*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx] = 0;
+      }
+      ++ iThreadIdx;
+    }
+  }
+
+  if ((*ppCtx)->pVpp) {
+    (*ppCtx)->pVpp->FreeSpatialPictures (*ppCtx);
+    delete (*ppCtx)->pVpp;
+    (*ppCtx)->pVpp = NULL;
+  }
+  FreeMemorySvc (ppCtx);
+  *ppCtx = NULL;
+}
+
+/*!
  * \brief   initialize Wels avc encoder core library
  * \pParam  ppCtx       sWelsEncCtx**
  * \pParam  pParam      SWelsSvcCodingParam*
@@ -2502,7 +2547,7 @@
   iRet = RequestMemorySvc (&pCtx, pExistingParasetList);
   if (iRet != 0) {
     WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), RequestMemorySvc failed return %d.", iRet);
-    FreeMemorySvc (&pCtx);
+    WelsUninitEncoderExt (&pCtx);
     return iRet;
   }
 
@@ -2514,12 +2559,12 @@
   if (pCtx->pVpp == NULL) {
     iRet = 1;
     WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pOut of memory in case new CWelsPreProcess().");
-    FreeMemorySvc (&pCtx);
+    WelsUninitEncoderExt (&pCtx);
     return iRet;
   }
   if ((iRet = pCtx->pVpp->AllocSpatialPictures (pCtx, pCtx->pSvcParam)) != 0) {
     WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pVPP alloc spatial pictures failed");
-    FreeMemorySvc (&pCtx);
+    WelsUninitEncoderExt (&pCtx);
     return iRet;
   }
 
@@ -2618,50 +2663,6 @@
   }
 }
 #endif
-/*!
- * \brief   uninitialize Wels encoder core library
- * \pParam  pEncCtx     sWelsEncCtx*
- * \return  none
- */
-void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) {
-  if (NULL == ppCtx || NULL == *ppCtx)
-    return;
-
-  WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
-           "WelsUninitEncoderExt(), pCtx= %p, iMultipleThreadIdc= %d.",
-           (void*) (*ppCtx), (*ppCtx)->pSvcParam->iMultipleThreadIdc);
-
-#if defined(STAT_OUTPUT)
-  StatOverallEncodingExt (*ppCtx);
-#endif
-
-  if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) {
-    const int32_t iThreadCount = (*ppCtx)->pSvcParam->iMultipleThreadIdc;
-    int32_t iThreadIdx = 0;
-
-    while (iThreadIdx < iThreadCount) {
-      int res = 0;
-      if ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]) {
-        WelsEventSignal (& (*ppCtx)->pSliceThreading->pExitEncodeEvent[iThreadIdx]);
-        WelsEventSignal (& (*ppCtx)->pSliceThreading->pThreadMasterEvent[iThreadIdx]);
-        res = WelsThreadJoin ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]); // waiting thread exit
-        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO, "WelsUninitEncoderExt(), pthread_join(pThreadHandles%d) return %d..",
-                 iThreadIdx,
-                 res);
-        (*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx] = 0;
-      }
-      ++ iThreadIdx;
-    }
-  }
-
-  if ((*ppCtx)->pVpp) {
-    (*ppCtx)->pVpp->FreeSpatialPictures (*ppCtx);
-    delete (*ppCtx)->pVpp;
-    (*ppCtx)->pVpp = NULL;
-  }
-  FreeMemorySvc (ppCtx);
-  *ppCtx = NULL;
-}
 
 /*!
  * \brief   get temporal level due to configuration and coding context