[x265] [PATCH] param: add more validation checks

sagar at multicorewareinc.com sagar at multicorewareinc.com
Fri Feb 28 05:13:53 CET 2014


# HG changeset patch
# User Sagar Kotecha <sagar at multicorewareinc.com>
# Date 1393483576 -19800
#      Thu Feb 27 12:16:16 2014 +0530
# Node ID 042bfd209e75257ba44f7d892443f6e7cfacabda
# Parent  9b0c9b76d90299fe446d6a544903a332f722541a
param: add more validation checks

diff -r 9b0c9b76d902 -r 042bfd209e75 source/common/common.h
--- a/source/common/common.h	Wed Feb 26 18:01:05 2014 +0530
+++ b/source/common/common.h	Thu Feb 27 12:16:16 2014 +0530
@@ -115,5 +115,6 @@
 int x265_exp2fix8(double x);
 void *x265_malloc(size_t size);
 void x265_free(void *ptr);
+int x265_atoi(const char *str, bool& bError);
 
 #endif // ifndef X265_COMMON_H
diff -r 9b0c9b76d902 -r 042bfd209e75 source/common/param.cpp
--- a/source/common/param.cpp	Wed Feb 26 18:01:05 2014 +0530
+++ b/source/common/param.cpp	Thu Feb 27 12:16:16 2014 +0530
@@ -361,7 +361,7 @@
     return 0;
 }
 
-static int x265_atoi(const char *str, bool& bError)
+int x265_atoi(const char *str, bool& bError)
 {
     char *end;
     int v = strtol(str, &end, 0);
@@ -791,12 +791,12 @@
     CHECK((1u << tuQTMaxLog2Size) > param->maxCUSize,
           "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
 
-    CHECK(param->tuQTMaxInterDepth < 1,
-          "QuadtreeTUMaxDepthInter must be greater than or equal to 1");
+    CHECK(param->tuQTMaxInterDepth < 1 || param->tuQTMaxInterDepth > 4,
+          "QuadtreeTUMaxDepthInter must be greater than 0 and less than 5");
     CHECK(param->maxCUSize < (1u << (tuQTMinLog2Size + param->tuQTMaxInterDepth - 1)),
           "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
-    CHECK(param->tuQTMaxIntraDepth < 1,
-          "QuadtreeTUMaxDepthIntra must be greater than or equal to 1");
+    CHECK(param->tuQTMaxIntraDepth < 1 || param->tuQTMaxIntraDepth > 4,
+          "QuadtreeTUMaxDepthIntra must be greater than 0 and less than 5");
     CHECK(param->maxCUSize < (1u << (tuQTMinLog2Size + param->tuQTMaxIntraDepth - 1)),
           "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
 
@@ -870,6 +870,29 @@
           "Default Display Window Top Offset must be 0 or greater");
     CHECK(param->defDispWinBottomOffset < 0,
           "Default Display Window Bottom Offset must be 0 or greater");
+    CHECK(param->rc.rfConstant < 0 || param->rc.rfConstant > 51,
+          "Valid quality based VBR range 0 - 51");
+    CHECK(param->bFrameAdaptive < 0 || param->bFrameAdaptive > 2,
+          "Valid adaptive b scheduling values 0 - none, 1 - fast, 2 - full");
+    CHECK(param->logLevel < -1 || param->logLevel > 3,
+          "Valid Logging level 0:ERROR 1:WARNING 2:INFO 3:DEBUG -1:NONE");
+    CHECK(param->scenecutThreshold < 0,
+          "scenecutThreshold must be greater than 0");
+    CHECK(param->rdPenalty < 0 || param->rdPenalty > 2,
+          "Valid penalty for 32x32 intra TU in non-I slices. 0:disabled 1:RD-penalty 2:maximum"); 
+    CHECK(param->keyframeMax < -1,
+          "Invalid max IDR period in frames. value should be greater than -1"); 
+    CHECK(param->decodedPictureHashSEI < 0 || param->decodedPictureHashSEI > 3,
+          "Invalid hash option. Decoded Picture Hash SEI 0: disabled, 1: MD5, 2: CRC, 3: Checksum");
+    CHECK(param->rc.vbvBufferSize < 0,
+          "Size of the vbv buffer can not be less than zero");
+    CHECK(param->rc.vbvMaxBitrate < 0,
+          "Maximum local bit rate can not be less than zero");
+    CHECK(param->rc.vbvBufferInit < 0 || param->rc.vbvBufferInit > 1,
+          "Valid VBV buffer occpancy range 0 - 1");
+    CHECK(param->rc.bitrate < 0,
+          "Target bitrate can not be less than zero");
+    CHECK(param->bFrameBias < 0, "Bias towards B frame decisions must be 0 or greater");
     return check_failed;
 }
 
diff -r 9b0c9b76d902 -r 042bfd209e75 source/x265.cpp
--- a/source/x265.cpp	Wed Feb 26 18:01:05 2014 +0530
+++ b/source/x265.cpp	Thu Feb 27 12:16:16 2014 +0530
@@ -399,7 +399,7 @@
 
 bool CLIOptions::parse(int argc, char **argv, x265_param* param)
 {
-    int berror = 0;
+    bool bError = 0;
     int help = 0;
     int cpuid = 0;
     int inputBitDepth = 8;
@@ -476,6 +476,7 @@
             }
 #define OPT(longname) \
     else if (!strcmp(long_options[long_options_index].name, longname))
+#define atoi(str) x265_atoi(str, bError)
 
             if (0) ;
             OPT("cpuid") cpuid = atoi(optarg);
@@ -486,7 +487,7 @@
             OPT("output") bitstreamfn = optarg;
             OPT("input") inputfn = optarg;
             OPT("recon") reconfn = optarg;
-            OPT("input-res") berror |= sscanf(optarg, "%dx%d", &param->sourceWidth, &param->sourceHeight) != 2;
+            OPT("input-res") bError |= sscanf(optarg, "%dx%d", &param->sourceWidth, &param->sourceHeight) != 2;
             OPT("input-depth") inputBitDepth = (uint32_t)atoi(optarg);
             OPT("recon-depth") reconFileBitDepth = (uint32_t)atoi(optarg);
             OPT("no-scenecut") param->scenecutThreshold = 0; // special handling
@@ -494,14 +495,15 @@
             OPT("preset") /* handled above */;
             OPT("tune")   /* handled above */;
             else
-                berror |= x265_param_parse(param, long_options[long_options_index].name, optarg);
+                bError |= !!x265_param_parse(param, long_options[long_options_index].name, optarg);
 
-            if (berror)
+            if (bError)
             {
                 const char *name = long_options_index > 0 ? long_options[long_options_index].name : argv[optind - 2];
                 x265_log(NULL, X265_LOG_ERROR, "invalid argument: %s = %s\n", name, optarg);
                 return true;
             }
+#undef atoi
 #undef OPT
         }
     }


More information about the x265-devel mailing list