shithub: openh264

Download patch

ref: f9f2bbf805ebb82d0cc46dd79aade2dfb264f046
parent: 6efeb0ef951d6196d3018e75d0860b1ada9025e0
parent: ecab683f0f7a118910cc11eefdb9b14a893c52cd
author: HaiboZhu <haibozhu@cisco.com>
date: Wed Sep 23 13:41:52 EDT 2015

Merge pull request #2127 from huili2/repos_DecoderConfigParam

move DecoderConfigParam into InitDecoder

--- a/codec/decoder/core/src/decoder.cpp
+++ b/codec/decoder/core/src/decoder.cpp
@@ -525,13 +525,6 @@
   if (NULL == pCtx || NULL == kpParam)
     return 1;
 
-  CMemoryAlign* pMa = pCtx->pMemAlign;
-
-  pCtx->pParam = (SDecodingParam*)pMa->WelsMallocz (sizeof (SDecodingParam), "SDecodingParam");
-
-  if (NULL == pCtx->pParam)
-    return 1;
-
   memcpy (pCtx->pParam, kpParam, sizeof (SDecodingParam));
   pCtx->eOutputColorFormat = pCtx->pParam->eOutputColorFormat;
   if (!pCtx->bParseOnly) {
@@ -538,6 +531,14 @@
     int32_t iRet = DecoderSetCsp (pCtx, pCtx->pParam->eOutputColorFormat);
     if (iRet)
       return iRet;
+  }
+  if ((pCtx->pParam->eEcActiveIdc > ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE)
+      || (pCtx->pParam->eEcActiveIdc < ERROR_CON_DISABLE)) {
+    WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING,
+             "eErrorConMethod (%d) not in range: (%d - %d). Set as default value: (%d).", pCtx->pParam->eEcActiveIdc,
+             ERROR_CON_DISABLE, ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE,
+             ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE);
+    pCtx->pParam->eEcActiveIdc = ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE;
   }
   pCtx->eErrorConMethod = pCtx->pParam->eEcActiveIdc;
 
--- a/codec/decoder/plus/inc/welsDecoderExt.h
+++ b/codec/decoder/plus/inc/welsDecoderExt.h
@@ -109,7 +109,7 @@
 PWelsDecoderContext     m_pDecContext;
 welsCodecTrace*         m_pWelsTrace;
 
-int32_t InitDecoder (const bool);
+int32_t InitDecoder (const SDecodingParam* pParam);
 void UninitDecoder (void);
 int32_t ResetDecoder();
 
--- a/codec/decoder/plus/src/welsDecoderExt.cpp
+++ b/codec/decoder/plus/src/welsDecoderExt.cpp
@@ -198,14 +198,10 @@
   }
 
   // H.264 decoder initialization,including memory allocation,then open it ready to decode
-  iRet = InitDecoder (pParam->bParseOnly);
+  iRet = InitDecoder (pParam);
   if (iRet)
     return iRet;
 
-  iRet = DecoderConfigParam (m_pDecContext, pParam);
-  if (iRet)
-    return iRet;
-
   return cmResultSuccess;
 }
 
@@ -241,11 +237,11 @@
 }
 
 // the return value of this function is not suitable, it need report failure info to upper layer.
-int32_t CWelsDecoder::InitDecoder (const bool bParseOnly) {
+int32_t CWelsDecoder::InitDecoder (const SDecodingParam* pParam) {
 
   WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
            "CWelsDecoder::init_decoder(), openh264 codec version = %s, ParseOnly = %d",
-           VERSION_NUMBER, (int32_t)bParseOnly);
+           VERSION_NUMBER, (int32_t)pParam->bParseOnly);
 
   if (m_pDecContext) //free
     UninitDecoder();
@@ -256,7 +252,17 @@
   m_pDecContext->pMemAlign = new CMemoryAlign (iCacheLineSize);
   WELS_VERIFY_RETURN_PROC_IF (1, (NULL == m_pDecContext->pMemAlign), UninitDecoder())
 
-  return WelsInitDecoder (m_pDecContext, bParseOnly, &m_pWelsTrace->m_sLogCtx);
+  WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, WelsInitDecoder (m_pDecContext, pParam->bParseOnly,
+                              &m_pWelsTrace->m_sLogCtx), UninitDecoder())
+
+  //check param and update decoder context
+  m_pDecContext->pParam = (SDecodingParam*) m_pDecContext->pMemAlign->WelsMallocz (sizeof (SDecodingParam),
+                          "SDecodingParam");
+  WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pParam), UninitDecoder());
+  int32_t iRet = DecoderConfigParam (m_pDecContext, pParam);
+  WELS_VERIFY_RETURN_IFNEQ (iRet, cmResultSuccess);
+
+  return cmResultSuccess;
 }
 
 int32_t CWelsDecoder::ResetDecoder() {
@@ -267,11 +273,7 @@
     SDecodingParam sPrevParam;
     memcpy (&sPrevParam, m_pDecContext->pParam, sizeof (SDecodingParam));
 
-    int32_t iRet = InitDecoder (m_pDecContext->bParseOnly);
-    if (iRet)
-      return iRet;
-
-    return DecoderConfigParam (m_pDecContext, &sPrevParam);
+    WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, InitDecoder (&sPrevParam), UninitDecoder());
   } else if (m_pWelsTrace != NULL) {
     WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "ResetDecoder() failed as decoder context null");
   }
--- a/test/decoder/DecUT_ParseSyntax.cpp
+++ b/test/decoder/DecUT_ParseSyntax.cpp
@@ -58,10 +58,25 @@
   return dsErrorFree;
 }
 
+void UninitDecoder (PWelsDecoderContext pCtx) {
+  if (NULL == pCtx)
+    return;
 
-int32_t InitDecoder (const bool bParseOnly, PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
+  WelsEndDecoder (pCtx);
+  if (NULL != pCtx->pMemAlign) {
+    delete pCtx->pMemAlign;
+    pCtx->pMemAlign = NULL;
+  }
+  if (NULL != pCtx) {
+    free (pCtx);
+    pCtx = NULL;
+  }
 
+}
 
+int32_t InitDecoder (const SDecodingParam* pParam, PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
+
+
   if (NULL == pCtx)
     return cmMallocMemeError;
 
@@ -71,7 +86,14 @@
       return cmMallocMemeError;
   }
 
-  return WelsInitDecoder (pCtx, bParseOnly, pLogCtx);
+  WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, WelsInitDecoder (pCtx, pParam->bParseOnly, pLogCtx), UninitDecoder (pCtx));
+  //check param and update decoder context
+  pCtx->pParam = (SDecodingParam*) pCtx->pMemAlign->WelsMallocz (sizeof (SDecodingParam), "SDecodingParam");
+  WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == pCtx->pParam), UninitDecoder (pCtx));
+  int32_t iRet = DecoderConfigParam (pCtx, pCtx->pParam);
+  WELS_VERIFY_RETURN_IFNEQ (iRet, cmResultSuccess);
+
+  return cmResultSuccess;
 }
 
 long Initialize (const SDecodingParam* pParam, PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
@@ -81,32 +103,13 @@
   }
 
   // H.264 decoder initialization,including memory allocation,then open it ready to decode
-  iRet = InitDecoder (pParam->bParseOnly, pCtx, pLogCtx);
+  iRet = InitDecoder (pParam, pCtx, pLogCtx);
   if (iRet)
     return iRet;
 
-  iRet = DecoderConfigParam (pCtx, pParam);
-  if (iRet)
-    return iRet;
-
   return cmResultSuccess;
 }
 
-void UninitDecoder (PWelsDecoderContext pCtx) {
-  if (NULL == pCtx)
-    return;
-
-  WelsEndDecoder (pCtx);
-  if (NULL != pCtx->pMemAlign) {
-    delete pCtx->pMemAlign;
-    pCtx->pMemAlign = NULL;
-  }
-  if (NULL != pCtx) {
-    free (pCtx);
-    pCtx = NULL;
-  }
-
-}
 class DecoderParseSyntaxTest : public ::testing::Test {
  public:
   virtual void SetUp() {