[x265-commits] [x265] lowres: no need to disable AQ on malloc failure, encoder ...
Steve Borho
steve at borho.org
Fri Feb 21 23:05:14 CET 2014
details: http://hg.videolan.org/x265/rev/ff3306fae207
branches:
changeset: 6246:ff3306fae207
user: Steve Borho <steve at borho.org>
date: Fri Feb 21 13:20:23 2014 -0600
description:
lowres: no need to disable AQ on malloc failure, encoder will abort
And thus there's no need to pass aqMode as an int pointer
Subject: [x265] common: improve error detection and handling in x265_param_parse
details: http://hg.videolan.org/x265/rev/0c3cb8fadb6f
branches:
changeset: 6247:0c3cb8fadb6f
user: Steve Borho <steve at borho.org>
date: Fri Feb 21 13:49:34 2014 -0600
description:
common: improve error detection and handling in x265_param_parse
* check return code of sscanf
* check int parameters are ints, bools are bools, etc
API users (not using the CLI and getopt)
* allow no-foo and nofoo
* allow foo-bar or foo_bar
* no-wpp=1 works as expected
Subject: [x265] common: disallow SAR numerator or denominator of 0
details: http://hg.videolan.org/x265/rev/f4bbbae743de
branches:
changeset: 6248:f4bbbae743de
user: Steve Borho <steve at borho.org>
date: Fri Feb 21 15:44:11 2014 -0600
description:
common: disallow SAR numerator or denominator of 0
Subject: [x265] common: fix --extended-sar CLI option atobool() was setting bError=true
details: http://hg.videolan.org/x265/rev/58ba28e0c9a5
branches:
changeset: 6249:58ba28e0c9a5
user: Steve Borho <steve at borho.org>
date: Fri Feb 21 15:48:17 2014 -0600
description:
common: fix --extended-sar CLI option atobool() was setting bError=true
Subject: [x265] common: only validate sarWidth and sarHeight when aspectRatioIdx == 255
details: http://hg.videolan.org/x265/rev/06d3b23ef3b6
branches:
changeset: 6250:06d3b23ef3b6
user: Steve Borho <steve at borho.org>
date: Fri Feb 21 16:04:33 2014 -0600
description:
common: only validate sarWidth and sarHeight when aspectRatioIdx == 255
diffstat:
source/Lib/TLibCommon/TComPic.cpp | 2 +-
source/common/common.cpp | 228 +++++++++++++++++++++++--------------
source/common/lowres.cpp | 5 +-
source/common/lowres.h | 2 +-
4 files changed, 143 insertions(+), 94 deletions(-)
diffs (truncated from 450 to 300 lines):
diff -r 66c56fc5dfb9 -r 06d3b23ef3b6 source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp Fri Feb 21 13:06:51 2014 -0600
+++ b/source/Lib/TLibCommon/TComPic.cpp Fri Feb 21 16:04:33 2014 -0600
@@ -103,7 +103,7 @@ bool TComPic::create(TEncCfg* cfg)
ok &= m_picSym->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
ok &= m_origPicYuv->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
ok &= m_reconPicYuv->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
- ok &= m_lowres.create(m_origPicYuv, cfg->param.bframes, &cfg->param.rc.aqMode);
+ ok &= m_lowres.create(m_origPicYuv, cfg->param.bframes, !!cfg->param.rc.aqMode);
if (ok && cfg->param.rc.vbvBufferSize > 0 && cfg->param.rc.vbvMaxBitrate > 0)
{
diff -r 66c56fc5dfb9 -r 06d3b23ef3b6 source/common/common.cpp
--- a/source/common/common.cpp Fri Feb 21 13:06:51 2014 -0600
+++ b/source/common/common.cpp Fri Feb 21 16:04:33 2014 -0600
@@ -53,8 +53,6 @@ int64_t x265_mdate(void)
#endif
}
-static int parseName(const char *arg, const char * const * names, int& error);
-
using namespace x265;
#define X265_ALIGNBYTES 32
@@ -560,9 +558,9 @@ int x265_check_params(x265_param *param)
|| param->aspectRatioIdc > 16)
&& param->aspectRatioIdc != 255,
"Sample Aspect Ratio must be 0-16 or 255");
- CHECK(param->sarWidth < 0,
+ CHECK(param->aspectRatioIdc == 255 && param->sarWidth <= 0,
"Sample Aspect Ratio width must be greater than 0");
- CHECK(param->sarHeight < 0,
+ CHECK(param->aspectRatioIdc == 255 && param->sarHeight <= 0,
"Sample Aspect Ratio height must be greater than 0");
CHECK(param->videoFormat < 0 || param->videoFormat > 5,
"Video Format must be Component component,"
@@ -725,30 +723,95 @@ void x265_print_params(x265_param *param
fflush(stderr);
}
+static int x265_atobool(const char *str, bool& bError)
+{
+ if (!strcmp(str, "1") ||
+ !strcmp(str, "true") ||
+ !strcmp(str, "yes"))
+ return 1;
+ if (!strcmp(str, "0") ||
+ !strcmp(str, "false") ||
+ !strcmp(str, "no"))
+ return 0;
+ bError = true;
+ return 0;
+}
+
+static int x265_atoi(const char *str, bool& bError)
+{
+ char *end;
+ int v = strtol(str, &end, 0);
+
+ if (end == str || *end != '\0')
+ bError = true;
+ return v;
+}
+
+static double x265_atof(const char *str, bool& bError)
+{
+ char *end;
+ double v = strtod(str, &end);
+
+ if (end == str || *end != '\0')
+ bError = true;
+ return v;
+}
+
+static int parseName(const char *arg, const char * const * names, bool& bError)
+{
+ for (int i = 0; names[i]; i++)
+ {
+ if (!strcmp(arg, names[i]))
+ {
+ return i;
+ }
+ }
+
+ return x265_atoi(arg, bError);
+}
+
+/* internal versions of string-to-int with additional error checking */
+#undef atoi
+#undef atof
+#define atoi(str) x265_atoi(str, bError)
+#define atof(str) x265_atof(str, bError)
+#define atobool(str) (bNameWasBool = true, x265_atobool(str, bError))
+
extern "C"
int x265_param_parse(x265_param *p, const char *name, const char *value)
{
- int berror = 0;
- int valuewasnull;
-
- /* Enable or Disable - default is Enable */
- int bvalue = 1;
+ bool bError = false;
+ bool bNameWasBool = false;
+ bool bValueWasNull = !value;
+ char nameBuf[64];
if (!name)
return X265_PARAM_BAD_NAME;
- if (!value)
- value = "1";
+ // s/_/-/g
+ if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
+ {
+ char *c;
+ strcpy(nameBuf, name);
+ while ((c = strchr(nameBuf, '_')))
+ {
+ *c = '-';
+ }
- if (!strncmp(name, "no-", 3))
+ name = nameBuf;
+ }
+
+ int i;
+ if ((!strncmp(name, "no-", 3) && (i = 3)) ||
+ (!strncmp(name, "no", 2) && (i = 2)))
{
- bvalue = 0;
- name += 3;
+ name += i;
+ value = !value || x265_atobool(value, bError) ? "false" : "true";
}
- else
- bvalue = 1;
-
- valuewasnull = !value;
+ else if (!value)
+ value = "true";
+ else if (value[0] == '=')
+ value++;
#if defined(_MSC_VER)
#pragma warning(disable: 4127) // conditional expression is constant
@@ -778,24 +841,24 @@ int x265_param_parse(x265_param *p, cons
OPT("threads") p->poolNumThreads = atoi(value);
OPT("frame-threads") p->frameNumThreads = atoi(value);
OPT("log") p->logLevel = atoi(value);
- OPT("wpp") p->bEnableWavefront = bvalue;
+ OPT("wpp") p->bEnableWavefront = atobool(value);
OPT("ctu") p->maxCUSize = (uint32_t)atoi(value);
OPT("tu-intra-depth") p->tuQTMaxIntraDepth = (uint32_t)atoi(value);
OPT("tu-inter-depth") p->tuQTMaxInterDepth = (uint32_t)atoi(value);
OPT("subme") p->subpelRefine = atoi(value);
OPT("merange") p->searchRange = atoi(value);
- OPT("rect") p->bEnableRectInter = bvalue;
- OPT("amp") p->bEnableAMP = bvalue;
+ OPT("rect") p->bEnableRectInter = atobool(value);
+ OPT("amp") p->bEnableAMP = atobool(value);
OPT("max-merge") p->maxNumMergeCand = (uint32_t)atoi(value);
- OPT("early-skip") p->bEnableEarlySkip = bvalue;
- OPT("fast-cbf") p->bEnableCbfFastMode = bvalue;
+ OPT("early-skip") p->bEnableEarlySkip = atobool(value);
+ OPT("fast-cbf") p->bEnableCbfFastMode = atobool(value);
OPT("rdpenalty") p->rdPenalty = atoi(value);
- OPT("tskip") p->bEnableTransformSkip = bvalue;
- OPT("no-tskip-fast") p->bEnableTSkipFast = bvalue;
- OPT("tskip-fast") p->bEnableTSkipFast = bvalue;
- OPT("strong-intra-smoothing") p->bEnableStrongIntraSmoothing = bvalue;
- OPT("constrained-intra") p->bEnableConstrainedIntra = bvalue;
- OPT("open-gop") p->bOpenGOP = bvalue;
+ OPT("tskip") p->bEnableTransformSkip = atobool(value);
+ OPT("no-tskip-fast") p->bEnableTSkipFast = atobool(value);
+ OPT("tskip-fast") p->bEnableTSkipFast = atobool(value);
+ OPT("strong-intra-smoothing") p->bEnableStrongIntraSmoothing = atobool(value);
+ OPT("constrained-intra") p->bEnableConstrainedIntra = atobool(value);
+ OPT("open-gop") p->bOpenGOP = atobool(value);
OPT("scenecut") p->scenecutThreshold = atoi(value);
OPT("keyint") p->keyframeMax = atoi(value);
OPT("min-keyint") p->keyframeMin = atoi(value);
@@ -804,19 +867,19 @@ int x265_param_parse(x265_param *p, cons
OPT("bframe-bias") p->bFrameBias = atoi(value);
OPT("b-adapt") p->bFrameAdaptive = atoi(value);
OPT("ref") p->maxNumReferences = atoi(value);
- OPT("weightp") p->bEnableWeightedPred = bvalue;
+ OPT("weightp") p->bEnableWeightedPred = atobool(value);
OPT("cbqpoffs") p->cbQpOffset = atoi(value);
OPT("crqpoffs") p->crQpOffset = atoi(value);
OPT("rd") p->rdLevel = atoi(value);
- OPT("signhide") p->bEnableSignHiding = bvalue;
- OPT("lft") p->bEnableLoopFilter = bvalue;
- OPT("sao") p->bEnableSAO = bvalue;
+ OPT("signhide") p->bEnableSignHiding = atobool(value);
+ OPT("lft") p->bEnableLoopFilter = atobool(value);
+ OPT("sao") p->bEnableSAO = atobool(value);
OPT("sao-lcu-bounds") p->saoLcuBoundary = atoi(value);
OPT("sao-lcu-opt") p->saoLcuBasedOptimization = atoi(value);
- OPT("ssim") p->bEnableSsim = bvalue;
- OPT("psnr") p->bEnablePsnr = bvalue;
+ OPT("ssim") p->bEnableSsim = atobool(value);
+ OPT("psnr") p->bEnablePsnr = atobool(value);
OPT("hash") p->decodedPictureHashSEI = atoi(value);
- OPT("b-pyramid") p->bBPyramid = bvalue;
+ OPT("b-pyramid") p->bBPyramid = atobool(value);
OPT("aq-mode") p->rc.aqMode = atoi(value);
OPT("aq-strength") p->rc.aqStrength = atof(value);
OPT("vbv-maxrate") p->rc.vbvMaxBitrate = atoi(value);
@@ -837,12 +900,13 @@ int x265_param_parse(x265_param *p, cons
p->rc.qp = atoi(value);
p->rc.rateControlMode = X265_RC_CQP;
}
- OPT("input-csp") p->internalCsp = parseName(value, x265_source_csp_names, berror);
- OPT("me") p->searchMethod = parseName(value, x265_motion_est_names, berror);
- OPT("cutree") p->rc.cuTree = bvalue;
- OPT("no-cutree") p->rc.cuTree = bvalue;
+ OPT("input-csp") p->internalCsp = parseName(value, x265_source_csp_names, bError);
+ OPT("me") p->searchMethod = parseName(value, x265_motion_est_names, bError);
+ OPT("cutree") p->rc.cuTree = atobool(value);
OPT("vui")
{
+ int bvalue = atobool(value);
+
p->bEnableVuiParametersPresentFlag = bvalue;
p->bEnableAspectRatioIdc = bvalue;
p->bEnableOverscanInfoPresentFlag = bvalue;
@@ -860,25 +924,25 @@ int x265_param_parse(x265_param *p, cons
OPT("sar")
{
p->bEnableVuiParametersPresentFlag = 1;
- p->bEnableAspectRatioIdc = bvalue;
+ p->bEnableAspectRatioIdc = atobool(value);
p->aspectRatioIdc = atoi(value);
}
OPT("extended-sar")
{
p->bEnableVuiParametersPresentFlag = 1;
- p->bEnableAspectRatioIdc = bvalue;
+ p->bEnableAspectRatioIdc = 1;
p->aspectRatioIdc = 255;
- sscanf(value, "%dx%d", &p->sarWidth, &p->sarHeight);
+ bError |= sscanf(value, "%dx%d", &p->sarWidth, &p->sarHeight) != 2;
}
OPT("overscan")
{
p->bEnableVuiParametersPresentFlag = 1;
if (!strcmp(value, "show"))
- p->bEnableOverscanInfoPresentFlag = bvalue;
+ p->bEnableOverscanInfoPresentFlag = atobool(value);
else if (!strcmp(value, "crop"))
{
- p->bEnableOverscanInfoPresentFlag = bvalue;
- p->bEnableOverscanAppropriateFlag = bvalue;
+ p->bEnableOverscanInfoPresentFlag = atobool(value);
+ p->bEnableOverscanAppropriateFlag = atobool(value);
}
else
p->bEnableOverscanInfoPresentFlag = -1;
@@ -886,7 +950,7 @@ int x265_param_parse(x265_param *p, cons
OPT("videoformat")
{
p->bEnableVuiParametersPresentFlag = 1;
- p->bEnableVideoSignalTypePresentFlag = bvalue;
+ p->bEnableVideoSignalTypePresentFlag = atobool(value);
if (!strcmp(value, "component"))
p->videoFormat = 0;
else if (!strcmp(value, "pal"))
@@ -905,14 +969,14 @@ int x265_param_parse(x265_param *p, cons
OPT("range")
{
p->bEnableVuiParametersPresentFlag = 1;
- p->bEnableVideoSignalTypePresentFlag = bvalue;
- p->bEnableVideoFullRangeFlag = bvalue;
+ p->bEnableVideoSignalTypePresentFlag = atobool(value);
+ p->bEnableVideoFullRangeFlag = atobool(value);
}
OPT("colorprim")
{
p->bEnableVuiParametersPresentFlag = 1;
- p->bEnableVideoSignalTypePresentFlag = bvalue;
- p->bEnableColorDescriptionPresentFlag = bvalue;
+ p->bEnableVideoSignalTypePresentFlag = atobool(value);
+ p->bEnableColorDescriptionPresentFlag = atobool(value);
if (!strcmp(value, "bt709"))
p->colorPrimaries = 1;
else if (!strcmp(value, "undef"))
@@ -935,8 +999,8 @@ int x265_param_parse(x265_param *p, cons
OPT("transfer")
{
p->bEnableVuiParametersPresentFlag = 1;
- p->bEnableVideoSignalTypePresentFlag = bvalue;
- p->bEnableColorDescriptionPresentFlag = bvalue;
+ p->bEnableVideoSignalTypePresentFlag = atobool(value);
+ p->bEnableColorDescriptionPresentFlag = atobool(value);
if (!strcmp(value, "bt709"))
p->transferCharacteristics = 1;
else if (!strcmp(value, "undef"))
@@ -971,8 +1035,8 @@ int x265_param_parse(x265_param *p, cons
OPT("colormatrix")
More information about the x265-commits
mailing list