shithub: openh264

Download patch

ref: 27a9af0b09a80165c5ec4c35d7784f2547564dd2
parent: ab4e0df75a80b4478f2ac9dc6113bf206bacf90e
author: Haibo Zhu <haibozhu@cisco.com>
date: Mon Aug 24 21:05:47 EDT 2015

Force reset decoder when out of memory error

--- a/codec/decoder/core/inc/error_code.h
+++ b/codec/decoder/core/inc/error_code.h
@@ -92,6 +92,7 @@
 ERR_INFO_READ_FAULT,
 ERR_INFO_READ_OVERFLOW,
 ERR_INFO_READ_LEADING_ZERO,
+ERR_INFO_UNINIT,
 /* Error from H.264 syntax elements parser: 1001-10000 */
 ERR_INFO_NO_PREFIX_CODE         = ERR_INFO_SYNTAX_BASE, // No start prefix code indication
 ERR_INFO_NO_PARAM_SETS,                                 // No SPS and/ PPS before sequence header
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -2152,6 +2152,7 @@
         WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
                  "DecodeCurrentAccessUnit()::::::PrefetchPic ERROR, pSps->iNumRefFrames:%d.",
                  pCtx->pSps->iNumRefFrames);
+        // The error code here need to be separated from the dsOutOfMemory
         pCtx->iErrorCode |= dsOutOfMemory;
         return ERR_INFO_REF_COUNT_OVERFLOW;
       }
--- a/codec/decoder/plus/inc/welsDecoderExt.h
+++ b/codec/decoder/plus/inc/welsDecoderExt.h
@@ -111,6 +111,7 @@
 
 int32_t InitDecoder (const bool);
 void UninitDecoder (void);
+int32_t ResetDecoder();
 
 #ifdef OUTPUT_BIT_STREAM
 WelsFileHandle* m_pFBS;
--- a/codec/decoder/plus/src/welsDecoderExt.cpp
+++ b/codec/decoder/plus/src/welsDecoderExt.cpp
@@ -258,6 +258,18 @@
   return WelsInitDecoder (m_pDecContext, bParseOnly, &m_pWelsTrace->m_sLogCtx);
 }
 
+int32_t CWelsDecoder::ResetDecoder() {
+  // TBC: need to be modified when context and trace point are null
+  if (m_pDecContext != NULL && m_pWelsTrace != NULL) {
+    WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "ResetDecoder(), context error code is %d",
+             m_pDecContext->iErrorCode);
+    return InitDecoder (m_pDecContext->bParseOnly);
+  } else if (m_pWelsTrace != NULL) {
+    WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "ResetDecoder() failed as decoder context null");
+  }
+  return ERR_INFO_UNINIT;
+}
+
 /*
  * Set Option
  */
@@ -487,7 +499,7 @@
     eNalType = m_pDecContext->sCurNalHead.eNalUnitType;
 
     if (m_pDecContext->iErrorCode & dsOutOfMemory) {
-      ForceResetParaSetStatusAndAUList (m_pDecContext);
+      ResetDecoder();
     }
     //for AVC bitstream (excluding AVC with temporal scalability, including TP), as long as error occur, SHOULD notify upper layer key frame loss.
     if ((IS_PARAM_SETS_NALS (eNalType) || NAL_UNIT_CODED_SLICE_IDR == eNalType) ||