shithub: openh264

Download patch

ref: 37fa5f554e81ef7fae826507c1b710eaae900bda
parent: e8d5108dbc5255447ad0ab28ddba83aaf8685d76
parent: 895c0ff635618bc45434ff6e505e94b5edac3fef
author: Licai Guo <[email protected]>
date: Tue Mar 18 05:51:32 EDT 2014

Merge pull request #513 from ruil2/encoder_interface

Encoder interface

--- a/codec/api/svc/codec_api.h
+++ b/codec/api/svc/codec_api.h
@@ -64,7 +64,7 @@
   virtual int EXTAPI Uninitialize() = 0;
 
   /*
-   * return: EVideoFrameType [IDR: videoFrameTypeIDR; P: videoFrameTypeP; ERROR: videoFrameTypeInvalid]
+   * return: 0 - success; otherwise -failed;
    */
   virtual int EXTAPI EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo) = 0;
   /*
--- a/codec/api/svc/codec_def.h
+++ b/codec/api/svc/codec_def.h
@@ -75,6 +75,7 @@
   cmUnkonwReason,
   cmMallocMemeError,                /*Malloc a memory error*/
   cmInitExpected,			  /*Initial action is expected*/
+  cmUnsupportedData,
 } CM_RETURN;
 
 
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -1730,8 +1730,8 @@
       break;
     case SM_AUTO_SLICE:
       iMaxSliceCount = MAX_SLICES_NUM;
-	  pDlp->sSliceCfg.sSliceArgument.uiSliceNum = kiCpuCores;
-	  if (pDlp->sSliceCfg.sSliceArgument.uiSliceNum > iMaxSliceCount){
+      pDlp->sSliceCfg.sSliceArgument.uiSliceNum = kiCpuCores;
+      if (pDlp->sSliceCfg.sSliceArgument.uiSliceNum > iMaxSliceCount){
         pDlp->sSliceCfg.sSliceArgument.uiSliceNum = iMaxSliceCount;
       }
       if (pDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -508,12 +508,29 @@
  */
 int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo) {
   if (! (kpSrcPic && m_pEncContext && m_bInitialFlag)) {
-    return videoFrameTypeInvalid;
+    return cmInitParaError;
   }
 
-  int32_t uiFrameType = videoFrameTypeInvalid;
-  uiFrameType = EncodeFrameInternal(kpSrcPic, pBsInfo);
+  const int32_t kiEncoderReturn = EncodeFrameInternal(kpSrcPic, pBsInfo);
 
+  switch (kiEncoderReturn) {
+  case ENC_RETURN_MEMALLOCERR:
+    WelsUninitEncoderExt (&m_pEncContext);
+    return cmMallocMemeError;
+  case ENC_RETURN_SUCCESS:
+  case ENC_RETURN_CORRECTED:
+    break;//continue processing
+  case ENC_RETURN_UNSUPPORTED_PARA:
+    return cmUnsupportedData;
+	break;
+  case ENC_RETURN_UNEXPECTED:
+    return cmUnkonwReason;
+  default:
+    WelsLog (m_pEncContext, WELS_LOG_ERROR, "unexpected return(%d) from WelsEncoderEncodeExt()!\n", kiEncoderReturn);
+    return cmUnkonwReason;
+  }
+
+
 #ifdef REC_FRAME_COUNT
   ++ m_uiCountFrameNum;
   WelsLog (m_pEncContext, WELS_LOG_INFO,
@@ -523,8 +540,7 @@
 #ifdef DUMP_SRC_PICTURE
   DumpSrcPicture (pSrc);
 #endif // DUMP_SRC_PICTURE
-
-  return uiFrameType;
+  return cmResultSuccess;
 }
 
 
@@ -539,19 +555,13 @@
   const int32_t kiEncoderReturn = WelsEncoderEncodeExt (m_pEncContext, pBsInfo, pSrcPic);
   XMMREG_PROTECT_LOAD(CWelsH264SVCEncoder);
 
-  switch (kiEncoderReturn) {
-  case ENC_RETURN_MEMALLOCERR:
+  if(kiEncoderReturn == ENC_RETURN_MEMALLOCERR) {
     WelsUninitEncoderExt (&m_pEncContext);
     return videoFrameTypeInvalid;
-  case ENC_RETURN_SUCCESS:
-  case ENC_RETURN_CORRECTED:
-    break;//continue processing
-  case ENC_RETURN_UNSUPPORTED_PARA:
-  case ENC_RETURN_UNEXPECTED:
+  }
+  else if((kiEncoderReturn != ENC_RETURN_SUCCESS)&&(kiEncoderReturn == ENC_RETURN_CORRECTED)){
+    WelsLog (m_pEncContext, WELS_LOG_ERROR, "unexpected return(%d) from EncodeFrameInternal()!\n", kiEncoderReturn);
     return videoFrameTypeInvalid;
-  default:
-    WelsLog (m_pEncContext, WELS_LOG_ERROR, "unexpected return(%d) from WelsEncoderEncodeExt()!\n", kiEncoderReturn);
-    return videoFrameTypeInvalid;
   }
 
   iFrameTypeReturned = pBsInfo->eOutputFrameType;
@@ -576,8 +586,6 @@
     break;
   }
 
-
-
   ///////////////////for test
 #ifdef OUTPUT_BIT_STREAM
   if (iFrameType != videoFrameTypeInvalid && iFrameType != videoFrameTypeSkip) {
@@ -625,7 +633,7 @@
   DumpSrcPicture (pSrcPicList[0]->pData[0]);
 #endif // DUMP_SRC_PICTURE
 
-  return iFrameType;
+  return kiEncoderReturn;
 
 }
 
--- a/test/BaseEncoderTest.cpp
+++ b/test/BaseEncoderTest.cpp
@@ -83,8 +83,8 @@
   pic.pData[2] = pic.pData[1] + (width*height>>2);
   while (in->read(buf.data(), frameSize) == frameSize) {
     rv = encoder_->EncodeFrame(&pic, &info);
-    ASSERT_TRUE(rv != videoFrameTypeInvalid);
-    if (rv != videoFrameTypeSkip && cbk != NULL) {
+    ASSERT_TRUE(rv == cmResultSuccess);
+    if (info.eOutputFrameType != videoFrameTypeSkip && cbk != NULL) {
       cbk->onEncodeFrame(info);
     }
   }