shithub: openh264

Download patch

ref: 76eed1a59828880f689a94116b3b14103ec5716a
parent: e39ce95e0f9aca06a80b1569d015141ba2fe4e14
author: ruil2 <[email protected]>
date: Wed Dec 20 10:36:58 EST 2017

return unsupported instead of uninitialize encoder

--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -396,10 +396,16 @@
 
 
 int CWelsH264SVCEncoder ::EncodeFrameInternal (const SSourcePicture*  pSrcPic, SFrameBSInfo* pBsInfo) {
+
+  if ((pSrcPic->iPicWidth < 16) || ((pSrcPic->iPicHeight < 16))) {
+    WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Don't support width(%d) or height(%d) which is less than 16!",
+             pSrcPic->iPicWidth, pSrcPic->iPicHeight);
+    return cmUnsupportedData;
+  }
+
   const int64_t kiBeforeFrameUs = WelsTime();
   const int32_t kiEncoderReturn = WelsEncoderEncodeExt (m_pEncContext, pBsInfo, pSrcPic);
   const int64_t kiCurrentFrameMs = (WelsTime() - kiBeforeFrameUs) / 1000;
-
   if ((kiEncoderReturn == ENC_RETURN_MEMALLOCERR) || (kiEncoderReturn == ENC_RETURN_MEMOVERFLOWFOUND)
       || (kiEncoderReturn == ENC_RETURN_VLCOVERFLOWFOUND)) {
     WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_DEBUG, "CWelsH264SVCEncoder::EncodeFrame() not succeed, err=%d",
@@ -735,7 +741,7 @@
     if ((sEncodingParam.iPicWidth  != m_pEncContext->pSvcParam->sDependencyLayers[m_pEncContext->pSvcParam->iSpatialLayerNum
          - 1].iActualWidth) ||
         (sEncodingParam.iPicHeight != m_pEncContext->pSvcParam->sDependencyLayers[m_pEncContext->pSvcParam->iSpatialLayerNum -
-            1].iActualHeight)) {
+                                                       1].iActualHeight)) {
       ++m_iSwitchTimes;
       m_bSwitch = true;
     }
--- a/test/api/encode_options_test.cpp
+++ b/test/api/encode_options_test.cpp
@@ -1928,7 +1928,7 @@
   int iSliceNum        = 1;
 
   EProfileIdc profileList[11] = {PRO_UNKNOWN, PRO_BASELINE, PRO_MAIN,
-                                 PRO_EXTENDED , PRO_HIGH , PRO_HIGH10,
+                                 PRO_EXTENDED, PRO_HIGH, PRO_HIGH10,
                                  PRO_HIGH422, PRO_HIGH444, PRO_CAVLC444,
                                  PRO_SCALABLE_BASELINE,
                                  PRO_SCALABLE_HIGH
@@ -2115,4 +2115,46 @@
     iRet = encoder_->Uninitialize();
     ASSERT_TRUE (iRet == cmResultSuccess) << "rv = " << iRet;
   }
+}
+
+TEST_F (EncodeDecodeTestAPI, UnsupportedVideoSizeInput) {
+  int iWidth       = 640;
+  int iHeight      = 360;
+  float fFrameRate = rand() % 30 + 0.5f;
+  int iSliceNum    = 1;
+  int iRet;
+
+  int iSrcWidth = rand() % 16;
+  int iSrcHeight = rand() % 16;
+
+  SEncParamExt sParam;
+  encoder_->GetDefaultParams (&sParam);
+  prepareParamDefault (1, iSliceNum, iWidth, iHeight, fFrameRate, &sParam);
+  sParam.bSimulcastAVC = rand() & 1; //0 or 1
+  sParam.iRCMode = RC_OFF_MODE;
+  sParam.iNumRefFrame = 1;
+  sParam.fMaxFrameRate = fFrameRate;
+  iRet = encoder_->InitializeExt (&sParam);
+  ASSERT_TRUE (iRet == cmResultSuccess) << "InitializeExt: iRet = " << iRet << " at " << sParam.iPicWidth << "x" <<
+                                        sParam.iPicHeight;
+
+//   int TraceLevel = WELS_LOG_DEBUG;
+//   encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &TraceLevel);
+  ASSERT_TRUE (InitialEncDec (iSrcWidth, iSrcHeight));
+
+  iRet = encoder_->EncodeFrame (&EncPic, &info);
+  ASSERT_TRUE (iRet == cmUnsupportedData) << "rv = " << iRet;
+
+  iSrcWidth = iWidth;
+  iSrcHeight = iHeight;
+
+  ASSERT_TRUE (InitialEncDec (iSrcWidth, iSrcHeight));
+
+  iRet = encoder_->EncodeFrame (&EncPic, &info);
+
+  ASSERT_TRUE (iRet == cmResultSuccess) << "rv = " << iRet;
+
+  iRet = encoder_->Uninitialize();
+  ASSERT_TRUE (iRet == cmResultSuccess) << "rv = " << iRet;
+
 }