Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libvmaf: add vmaf_feature_dictionary_free() #879

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libvmaf/include/libvmaf/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ typedef struct VmafFeatureDictionary VmafFeatureDictionary;
int vmaf_feature_dictionary_set(VmafFeatureDictionary **dict, const char *key,
const char *val);

int vmaf_feature_dictionary_free(VmafFeatureDictionary **dict);

#endif /* __VMAF_FEATURE_H__ */
4 changes: 3 additions & 1 deletion libvmaf/include/libvmaf/libvmaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ int vmaf_use_features_from_model_collection(VmafContext *vmaf,
* Register specific feature extractor.
* Useful when a specific/additional feature is required, usually one which
* is not already provided by a model via `vmaf_use_features_from_model()`.
* This may be called multiple times.
* This may be called multiple times. `VmafContext` will take ownership of the
* `VmafFeatureDictionary` (`opts_dict`). Use `vmaf_feature_dictionary_free()`
* only in the case of failure.
*
* @param vmaf The VMAF context allocated with `vmaf_init()`.
*
Expand Down
5 changes: 5 additions & 0 deletions libvmaf/src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,8 @@ int vmaf_feature_dictionary_set(VmafFeatureDictionary **dict, const char *key,
return vmaf_dictionary_set((VmafDictionary**)dict, key, val,
VMAF_DICT_NORMALIZE_NUMERICAL_VALUES);
}

int vmaf_feature_dictionary_free(VmafFeatureDictionary **dict)
{
return vmaf_dictionary_free((VmafDictionary**)dict);
}
17 changes: 17 additions & 0 deletions libvmaf/test/test_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,28 @@ static char *test_vmaf_dictionary_normalize_numerical_val()
return NULL;
}


static char *test_vmaf_feature_dictionary()
{
int err = 0;

VmafFeatureDictionary *dict = NULL;
err = vmaf_feature_dictionary_set(&dict, "option", "value");
mu_assert("problem during vmaf_feature_dictionary_set", !err);
mu_assert("dictionary should not be NULL after setting first option", dict);
err = vmaf_feature_dictionary_free(&dict);
mu_assert("problem during vmaf_feature_dictionary_free", !err);
mu_assert("dictionary should be NULL after free", !dict);

return NULL;
}

char *run_tests()
{
mu_run_test(test_vmaf_dictionary);
mu_run_test(test_vmaf_dictionary_merge);
mu_run_test(test_vmaf_dictionary_compare);
mu_run_test(test_vmaf_dictionary_normalize_numerical_val);
mu_run_test(test_vmaf_feature_dictionary);
return NULL;
}