shithub: openh264

Download patch

ref: 8d2883277ce36d1c71a3c626b348781bde9cd704
parent: 991b05fb69056e753d181bfd31d56c6502c77b6d
parent: 6fe05b0996ce7c68576bfcefb439498144064d49
author: HaiboZhu <haibozhu@cisco.com>
date: Mon Nov 16 05:26:45 EST 2015

Merge pull request #2236 from sijchen/thp82

[Encoder] add error handling of task returns

--- a/codec/encoder/core/inc/wels_task_encoder.h
+++ b/codec/encoder/core/inc/wels_task_encoder.h
@@ -68,6 +68,8 @@
     return WELS_ENC_TASK_ENCODE_FIXED_SLICE;
   }
  protected:
+  WelsErrorType m_eTaskResult;
+
   int32_t QueryEmptyThread (bool* pThreadBsBufferUsage);
 
   sWelsEncCtx* m_pCtx;
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -55,7 +55,7 @@
 
 namespace WelsEnc {
 
-CWelsSliceEncodingTask::CWelsSliceEncodingTask (sWelsEncCtx* pCtx, const int32_t iSliceIdx) {
+CWelsSliceEncodingTask::CWelsSliceEncodingTask (sWelsEncCtx* pCtx, const int32_t iSliceIdx) : m_eTaskResult(ENC_RETURN_SUCCESS) {
   m_pCtx = pCtx;
   m_iSliceIdx = iSliceIdx;
 }
@@ -66,13 +66,13 @@
 WelsErrorType CWelsSliceEncodingTask::Execute() {
   WelsThreadSetName ("OpenH264Enc_CWelsSliceEncodingTask_Execute");
 
-  int32_t iReturn = InitTask();
-  WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
+  m_eTaskResult = InitTask();
+  WELS_VERIFY_RETURN_IFNEQ (m_eTaskResult, ENC_RETURN_SUCCESS)
 
-  iReturn = ExecuteTask();
+  m_eTaskResult = ExecuteTask();
 
   FinishTask();
-  return ENC_RETURN_SUCCESS;
+  return m_eTaskResult;
 }
 
 WelsErrorType CWelsSliceEncodingTask::SetBoundary (int32_t iStartIdx,  int32_t iEndIdx) {
@@ -131,6 +131,13 @@
   WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
            "[MT] CWelsSliceEncodingTask()FinishTask for m_iSliceIdx %d, unlock thread %d",
            m_iSliceIdx, m_iThreadIdx);
+
+  //sync multi-threading error
+  WelsMutexLock (&m_pCtx->mutexEncoderError);
+  if (ENC_RETURN_SUCCESS != m_eTaskResult) {
+    m_pCtx->iEncoderError |= m_eTaskResult;
+  }
+  WelsMutexUnlock (&m_pCtx->mutexEncoderError);
 }
 
 WelsErrorType CWelsSliceEncodingTask::ExecuteTask() {