Add --crypto parameter

This commit is contained in:
Ari Koivula 2016-06-07 10:55:26 +03:00 committed by Wassim Hamidouche
parent 02308d1ba6
commit 60ea8a359f
4 changed files with 67 additions and 3 deletions

View file

@ -23,7 +23,7 @@ AC_CONFIG_SRCDIR([src/encmain.c])
#
# Here is a somewhat sane guide to lib versioning: http://apr.apache.org/versioning.html
ver_major=3
ver_minor=6
ver_minor=7
ver_release=0
# Prevents configure from adding a lot of defines to the CFLAGS

View file

@ -107,6 +107,7 @@ int kvz_config_init(kvz_config *cfg)
cfg->calc_psnr = true;
cfg->mv_constraint = KVZ_MV_CONSTRAIN_NONE;
cfg->crypto_features = KVZ_CRYPTO_OFF;
return 1;
}
@ -137,11 +138,11 @@ static int atobool(const char *str)
return 0;
}
static int parse_enum(const char *arg, const char * const *names, int8_t *dst)
static int parse_enum_n(const char *arg, unsigned num_chars, const char * const *names, int8_t *dst)
{
int8_t i;
for (i = 0; names[i]; i++) {
if (!strcmp(arg, names[i])) {
if (!strncmp(arg, names[i], num_chars)) {
*dst = i;
return 1;
}
@ -150,6 +151,11 @@ static int parse_enum(const char *arg, const char * const *names, int8_t *dst)
return 0;
}
static int parse_enum(const char *arg, const char * const *names, int8_t *dst)
{
return parse_enum_n(arg, 255, names, dst);
}
static int parse_tiles_specification(const char* const arg, int32_t * const ntiles, int32_t** const array) {
const char* current_arg = NULL;
int32_t current_value;
@ -289,6 +295,8 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
static const char * const hash_names[] = { "none", "checksum", "md5", NULL };
static const char * const cu_split_termination_names[] = { "zero", "off", NULL };
static const char * const crypto_toggle_names[] = { "off", "on", NULL };
static const char * const crypto_feature_names[] = { "feature1", "feature2", "feature3", "feature4", NULL };
static const char * const preset_values[11][32] = {
{
@ -838,6 +846,47 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
cfg->cu_split_termination = mode;
return result;
}
else if OPT("crypto")
{
// on, off, feature1+feature2
const char *token_begin = value;
const char *cur = token_begin;
cfg->crypto_features = KVZ_CRYPTO_OFF;
// If value is on or off, set all features to on or off.
int8_t toggle = 0;
if (parse_enum(token_begin, crypto_toggle_names, &toggle)) {
if (toggle == 1) {
cfg->crypto_features = KVZ_CRYPTO_ON;
}
return 1;
}
// Try and parse "feature1+feature2" type list.
for (;;) {
if (*cur == '+' || *cur == '\0') {
int8_t feature = 0;
int num_chars = cur - token_begin;
if (parse_enum_n(token_begin, num_chars, crypto_feature_names, &feature)) {
cfg->crypto_features |= (1 << feature);
} else {
cfg->crypto_features = KVZ_CRYPTO_OFF;
return 0;
}
token_begin = cur + 1;
}
if (*cur == '\0') {
break;
} else {
++cur;
}
}
return 1;
}
else
return 0;
#undef OPT

View file

@ -106,6 +106,7 @@ static const struct option long_options[] = {
{ "mv-constraint", required_argument, NULL, 0 },
{ "hash", required_argument, NULL, 0 },
{"cu-split-termination",required_argument, NULL, 0 },
{ "crypto", required_argument, NULL, 0 },
{0, 0, 0, 0}
};

View file

@ -138,6 +138,19 @@ enum kvz_cu_split_termination
KVZ_CU_SPLIT_TERMINATION_OFF = 1
};
/**
* \brief Enable and disable crypto features.
* \since 3.7.0
*/
enum kvz_crypto_features {
KVZ_CRYPTO_OFF = 0,
KVZ_CRYPTO_FEATURE1 = (1 << 0),
KVZ_CRYPTO_FEATURE2 = (1 << 1),
KVZ_CRYPTO_FEATURE3 = (1 << 2),
KVZ_CRYPTO_FEATURE4 = (1 << 3),
KVZ_CRYPTO_ON = (1 << 4) - 1,
};
/**
* \brief GoP picture configuration.
*/
@ -247,6 +260,7 @@ typedef struct kvz_config
enum kvz_cu_split_termination cu_split_termination; /*!< \brief Mode of cu split termination. */
enum kvz_crypto_features crypto_features; /*!< \since 3.7.0 */
} kvz_config;
/**