shithub: openh264

Download patch

ref: 4048b9791a9bdcd431bc7315a6a86029ee9034e6
parent: 3022d4f6559596e0a6a1fae4d638f3c02f7d2a9e
parent: 94d1976a4e233bc0f74998482d9660704c7a0047
author: huili2 <[email protected]>
date: Thu Mar 5 04:39:46 EST 2015

Merge pull request #1834 from sijchen/check_param

complete parameter checking related to loop-filter-idc

--- a/codec/api/svc/codec_def.h
+++ b/codec/api/svc/codec_def.h
@@ -121,6 +121,17 @@
 #define FRAME_NUM_PARAM_SET		(-1)
 #define FRAME_NUM_IDR			0
 
+/**
+ * @brief eDeblockingIdc
+ */
+enum {
+  DEBLOCKING_IDC_0 = 0,
+  DEBLOCKING_IDC_1 = 1,
+  DEBLOCKING_IDC_2 = 2
+};
+#define DEBLOCKING_OFFSET (6)
+#define DEBLOCKING_OFFSET_MINUS (-6)
+
 /* Error Tools definition */
 typedef unsigned short ERR_TOOL;
 
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -185,7 +185,7 @@
     if (pCfg->bEnableSceneChangeDetect == false) {
       pCfg->bEnableSceneChangeDetect = true;
       WelsLog (pLogCtx, WELS_LOG_WARNING,
-               "ParamValidation(), screen change detection should be turned on,change bEnableSceneChangeDetect as true");
+               "ParamValidation(), screen change detection should be turned on, change bEnableSceneChangeDetect as true");
     }
 
   }
@@ -196,12 +196,22 @@
       SSpatialLayerConfig* fDlp = &pCfg->sSpatialLayers[i];
       if ((fDlp->iVideoWidth > iFinalWidth) || (fDlp->iVideoHeight > iFinalHeight)) {
         WelsLog (pLogCtx, WELS_LOG_ERROR,
-                 "ParamValidation,Invalid resolution layer(%d) resolution(%d x %d) shoudl be less than the highest spatial layer resolution(%d x %d) ",
+                 "ParamValidation,Invalid resolution layer(%d) resolution(%d x %d) should be less than the highest spatial layer resolution(%d x %d) ",
                  i, fDlp->iVideoWidth, fDlp->iVideoHeight, iFinalWidth, iFinalHeight);
         return ENC_RETURN_UNSUPPORTED_PARA;
       }
     }
   }
+
+  if (!CheckInRangeCloseOpen (pCfg->iLoopFilterDisableIdc, DEBLOCKING_IDC_0, DEBLOCKING_IDC_2 + 1) ||
+      !CheckInRangeCloseOpen (pCfg->iLoopFilterAlphaC0Offset, DEBLOCKING_OFFSET_MINUS, DEBLOCKING_OFFSET + 1) ||
+      !CheckInRangeCloseOpen (pCfg->iLoopFilterBetaOffset, DEBLOCKING_OFFSET_MINUS, DEBLOCKING_OFFSET + 1)) {
+    WelsLog (pLogCtx, WELS_LOG_ERROR,
+             "ParamValidation, Invalid iLoopFilterDisableIdc(%d) or iLoopFilterAlphaC0Offset(%d) or iLoopFilterBetaOffset(%d)!",
+             pCfg->iLoopFilterDisableIdc, pCfg->iLoopFilterAlphaC0Offset, pCfg->iLoopFilterBetaOffset);
+    return ENC_RETURN_UNSUPPORTED_PARA;
+  }
+
   for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) {
     SSpatialLayerInternal* fDlp = &pCfg->sDependencyLayers[i];
     SSpatialLayerConfig* pConfig = &pCfg->sSpatialLayers[i];
@@ -312,12 +322,6 @@
     WelsLog (pLogCtx, WELS_LOG_ERROR,
              "ParamValidationExt(), uiIntraPeriod(%d) should be multiple of uiGopSize(%d) or -1 specified!",
              pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize);
-    return ENC_RETURN_UNSUPPORTED_PARA;
-  }
-  if (pCodingParam->iLoopFilterDisableIdc < 0 || pCodingParam->iLoopFilterDisableIdc > 6) {
-    WelsLog (pLogCtx, WELS_LOG_ERROR,
-             "ParamValidationExt(), iLoopFilterDisableIdc(%d) must be between 0 and 6",
-             pCodingParam->iLoopFilterDisableIdc);
     return ENC_RETURN_UNSUPPORTED_PARA;
   }