shithub: openh264

Download patch

ref: 5d9b95288f47f703c2dd804cd0510de2812a236c
parent: 7da20f873848199a9ad41cd9cf6d5591bad5f460
parent: 27a9af0b09a80165c5ec4c35d7784f2547564dd2
author: zhilwang <zhilwang@cisco.com>
date: Wed Aug 26 12:14:32 EDT 2015

Merge pull request #2083 from HaiboZhu/Bugfix_OutOfMemory_post_process

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
@@ -259,6 +259,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
  */
@@ -488,7 +500,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) ||