From ade5e719b5e3037ebb64163bc490572980203a9d Mon Sep 17 00:00:00 2001 From: Yigithan Yigit Date: Fri, 19 Jul 2024 18:17:42 +0300 Subject: [PATCH] Renaming old structures/files for better naming and new struct for metadata instead of passing as paramaters --- libvmaf/include/libvmaf/libvmaf.h | 7 +++++- libvmaf/src/feature/feature_collector.c | 13 ++++++----- libvmaf/src/feature/feature_collector.h | 4 ++-- libvmaf/src/libvmaf.c | 2 +- libvmaf/src/meson.build | 2 +- ...ropagate_metadata.c => metadata_handler.c} | 18 +++++++-------- ...ropagate_metadata.h => metadata_handler.h} | 22 +++++++++---------- libvmaf/test/meson.build | 8 +++---- libvmaf/test/test_predict.c | 8 +++---- libvmaf/test/test_propagate_metadata.c | 8 +++---- 10 files changed, 50 insertions(+), 42 deletions(-) rename libvmaf/src/{propagate_metadata.c => metadata_handler.c} (75%) rename libvmaf/src/{propagate_metadata.h => metadata_handler.h} (64%) diff --git a/libvmaf/include/libvmaf/libvmaf.h b/libvmaf/include/libvmaf/libvmaf.h index 4e032768d..cbe734653 100644 --- a/libvmaf/include/libvmaf/libvmaf.h +++ b/libvmaf/include/libvmaf/libvmaf.h @@ -253,8 +253,13 @@ int vmaf_score_at_index_model_collection(VmafContext *vmaf, int vmaf_feature_score_at_index(VmafContext *vmaf, const char *feature_name, double *score, unsigned index); +typedef struct VmafMetadata { + char *key; + double value; +} VmafMetadata; + typedef struct VmafMetadataConfig { - void (*callback)(void *, const char *, double); + void (*callback)(void *, VmafMetadata *); void *data; } VmafMetadataConfig; diff --git a/libvmaf/src/feature/feature_collector.c b/libvmaf/src/feature/feature_collector.c index 3c7a45f5e..1df9a8779 100644 --- a/libvmaf/src/feature/feature_collector.c +++ b/libvmaf/src/feature/feature_collector.c @@ -24,7 +24,7 @@ #include #include "dict.h" -#include "propagate_metadata.h" +#include "metadata_handler.h" #include "feature_collector.h" #include "feature_name.h" #include "libvmaf/libvmaf.h" @@ -282,7 +282,7 @@ int vmaf_feature_collector_register_metadata(VmafFeatureCollector *feature_colle if (!feature_collector) return -EINVAL; if (!metadata_config) return -EINVAL; - VmafMetadata *metadata = feature_collector->metadata; + VmafCallbackList *metadata = feature_collector->metadata; int err = vmaf_metadata_append(metadata, metadata_config); if (err) return err; @@ -346,7 +346,7 @@ int vmaf_feature_collector_append(VmafFeatureCollector *feature_collector, int res = 0; - VmafMetadataNode *metadata_iter = feature_collector->metadata ? + VmafCallbackItem *metadata_iter = feature_collector->metadata ? feature_collector->metadata->head : NULL; while(metadata_iter) { @@ -354,7 +354,6 @@ int vmaf_feature_collector_append(VmafFeatureCollector *feature_collector, while (model_iter) { VmafModel *model = model_iter->model; - double score = 0.0; pthread_mutex_unlock(&(feature_collector->lock)); res = vmaf_feature_collector_get_score(feature_collector, model->name, &score, picture_index); @@ -370,7 +369,11 @@ int vmaf_feature_collector_append(VmafFeatureCollector *feature_collector, if (res) goto unlock; char key[128]; snprintf(key, sizeof(key), "%s_%d", model->name, picture_index); - metadata_iter->callback(metadata_iter->data, key, score); + VmafMetadata data = { + .key = key, + .value = score, + }; + metadata_iter->callback(metadata_iter->data, &data); model_iter = model_iter->next; } metadata_iter = metadata_iter->next; diff --git a/libvmaf/src/feature/feature_collector.h b/libvmaf/src/feature/feature_collector.h index 31dacde49..0d10846dc 100644 --- a/libvmaf/src/feature/feature_collector.h +++ b/libvmaf/src/feature/feature_collector.h @@ -25,7 +25,7 @@ #include "dict.h" #include "model.h" -#include "propagate_metadata.h" +#include "metadata_handler.h" typedef struct { char *name; @@ -52,7 +52,7 @@ typedef struct VmafPredictModel { typedef struct VmafFeatureCollector { FeatureVector **feature_vector; AggregateVector aggregate_vector; - VmafMetadata *metadata; + VmafCallbackList *metadata; VmafPredictModel *models; unsigned cnt, capacity; struct { clock_t begin, end; } timer; diff --git a/libvmaf/src/libvmaf.c b/libvmaf/src/libvmaf.c index 724387e69..92113e37f 100644 --- a/libvmaf/src/libvmaf.c +++ b/libvmaf/src/libvmaf.c @@ -32,7 +32,7 @@ #include "cpu.h" #include "feature/feature_extractor.h" #include "feature/feature_collector.h" -#include "propagate_metadata.h" +#include "metadata_handler.h" #include "fex_ctx_vector.h" #include "log.h" #include "model.h" diff --git a/libvmaf/src/meson.build b/libvmaf/src/meson.build index 1255e2431..d2a3833d1 100644 --- a/libvmaf/src/meson.build +++ b/libvmaf/src/meson.build @@ -462,7 +462,7 @@ libvmaf_sources = [ src_dir + 'pdjson.c', src_dir + 'log.c', src_dir + 'framesync.c', - src_dir + 'propagate_metadata.c', + src_dir + 'metadata_handler.c', ] if is_cuda_enabled diff --git a/libvmaf/src/propagate_metadata.c b/libvmaf/src/metadata_handler.c similarity index 75% rename from libvmaf/src/propagate_metadata.c rename to libvmaf/src/metadata_handler.c index a812661da..497499dad 100644 --- a/libvmaf/src/propagate_metadata.c +++ b/libvmaf/src/metadata_handler.c @@ -20,13 +20,13 @@ #include #include -#include "propagate_metadata.h" +#include "metadata_handler.h" -int vmaf_metadata_init(VmafMetadata **const metadata) +int vmaf_metadata_init(VmafCallbackList **const metadata) { if (!metadata) return -EINVAL; - VmafMetadata *const metadata_s = *metadata = + VmafCallbackList *const metadata_s = *metadata = malloc(sizeof(*metadata_s)); if (!metadata_s) goto fail; @@ -38,13 +38,13 @@ int vmaf_metadata_init(VmafMetadata **const metadata) return -ENOMEM; } -int vmaf_metadata_append(VmafMetadata *metadata, const VmafMetadataConfig *metadata_config) +int vmaf_metadata_append(VmafCallbackList *metadata, const VmafMetadataConfig *metadata_config) { if (!metadata) return -EINVAL; if (!metadata_config) return -EINVAL; if (!metadata_config->callback) return -EINVAL; - VmafMetadataNode *node = malloc(sizeof(*node)); + VmafCallbackItem *node = malloc(sizeof(*node)); if (!node) goto fail; memset(node, 0, sizeof(*node)); @@ -54,7 +54,7 @@ int vmaf_metadata_append(VmafMetadata *metadata, const VmafMetadataConfig *metad if (!metadata->head) { metadata->head = node; } else { - VmafMetadataNode *iter = metadata->head; + VmafCallbackItem *iter = metadata->head; while (iter->next) iter = iter->next; iter->next = node; } @@ -65,13 +65,13 @@ int vmaf_metadata_append(VmafMetadata *metadata, const VmafMetadataConfig *metad return -ENOMEM; } -int vmaf_metadata_destroy(VmafMetadata *metadata) +int vmaf_metadata_destroy(VmafCallbackList *metadata) { if (!metadata) return -EINVAL; - VmafMetadataNode *iter = metadata->head; + VmafCallbackItem *iter = metadata->head; while (iter) { - VmafMetadataNode *next = iter->next; + VmafCallbackItem *next = iter->next; free(iter); iter = next; } diff --git a/libvmaf/src/propagate_metadata.h b/libvmaf/src/metadata_handler.h similarity index 64% rename from libvmaf/src/propagate_metadata.h rename to libvmaf/src/metadata_handler.h index 6f2ab6738..eb4407d7a 100644 --- a/libvmaf/src/propagate_metadata.h +++ b/libvmaf/src/metadata_handler.h @@ -21,21 +21,21 @@ #include "libvmaf/libvmaf.h" -typedef struct VmafMetadataNode { - void (*callback)(void *, const char *, double); +typedef struct VmafCallbackItem { + void (*callback)(void *, VmafMetadata *); void *data; - struct VmafMetadataNode *next; -} VmafMetadataNode; + struct VmafCallbackItem *next; +} VmafCallbackItem; -typedef struct VmafMetadata{ - VmafMetadataNode *head; -} VmafMetadata; +typedef struct VmafCallbackList{ + VmafCallbackItem *head; +} VmafCallbackList; -int vmaf_metadata_init(VmafMetadata **const metadata); +int vmaf_metadata_init(VmafCallbackList **const metadata); -int vmaf_metadata_append(VmafMetadata *metadata, - const VmafMetadataConfig *metadata_config); +int vmaf_metadata_append(VmafCallbackList *metadata, + const VmafMetadataConfig *metadata_config); -int vmaf_metadata_destroy(VmafMetadata *metadata); +int vmaf_metadata_destroy(VmafCallbackList *metadata); #endif // !__VMAF_PROPAGATE_METADATA_H__ diff --git a/libvmaf/test/meson.build b/libvmaf/test/meson.build index 849de3215..e8d943e98 100644 --- a/libvmaf/test/meson.build +++ b/libvmaf/test/meson.build @@ -18,12 +18,12 @@ test_picture = executable('test_picture', ) test_propagate_metadata = executable('test_propagate_metadata', - ['test.c', 'test_propagate_metadata.c', '../src/propagate_metadata.c'], + ['test.c', 'test_propagate_metadata.c', '../src/metadata_handler.c'], include_directories : [libvmaf_inc, test_inc, include_directories('../src/')], ) test_feature_collector = executable('test_feature_collector', - ['test.c', 'test_feature_collector.c', '../src/log.c', '../src/predict.c', '../src/svm.cpp', '../src/propagate_metadata.c'], + ['test.c', 'test_feature_collector.c', '../src/log.c', '../src/predict.c', '../src/svm.cpp', '../src/metadata_handler.c'], include_directories : [libvmaf_inc, test_inc, include_directories('../src/feature/'), include_directories('../src')], link_with : get_option('default_library') == 'both' ? libvmaf.get_static_lib() : libvmaf, dependencies: cuda_dependency @@ -50,7 +50,7 @@ test_model = executable('test_model', ) test_predict = executable('test_predict', - ['test.c', 'test_predict.c', '../src/dict.c', '../src/propagate_metadata.c', + ['test.c', 'test_predict.c', '../src/dict.c', '../src/metadata_handler.c', '../src/feature/feature_collector.c', '../src/feature/alias.c', '../src/model.c', '../src/svm.cpp', '../src/log.c', '../src/read_json_model.c', '../src/pdjson.c', json_model_c_sources, '../src/feature/feature_name.c', '../src/feature/feature_extractor.c',], include_directories : [libvmaf_inc, test_inc, include_directories('../src/')], @@ -63,7 +63,7 @@ test_predict = executable('test_predict', test_feature_extractor = executable('test_feature_extractor', ['test.c', 'test_feature_extractor.c', '../src/mem.c', '../src/picture.c', '../src/ref.c', '../src/dict.c', '../src/opt.c', '../src/log.c', '../src/predict.c', '../src/svm.cpp', - '../src/propagate_metadata.c'], + '../src/metadata_handler.c'], include_directories : [libvmaf_inc, test_inc, include_directories('../src/')], dependencies : [math_lib, stdatomic_dependency, thread_lib, cuda_dependency], objects : [ diff --git a/libvmaf/test/test_predict.c b/libvmaf/test/test_predict.c index 7339bceff..a94df4792 100644 --- a/libvmaf/test/test_predict.c +++ b/libvmaf/test/test_predict.c @@ -19,7 +19,7 @@ #include #include "feature/feature_collector.h" -#include "propagate_metadata.h" +#include "metadata_handler.h" #include "test.h" #include "predict.h" #include "predict.c" @@ -66,13 +66,13 @@ static char *test_predict_score_at_index() } -void set_meta(void *data, const char *key, double d) +void set_meta(void *data, VmafMetadata *metadata) { if (!data) return; MetaStruct *meta = data; char value[128]; - snprintf(value, sizeof(value), "%f", d); - vmaf_dictionary_set(meta->metadata, key, value, meta->flags); + snprintf(value, sizeof(value), "%f", metadata->value); + vmaf_dictionary_set(meta->metadata, metadata->key, value, meta->flags); } static char* test_propagate_metadata() diff --git a/libvmaf/test/test_propagate_metadata.c b/libvmaf/test/test_propagate_metadata.c index 9d2fd05df..e87b78091 100644 --- a/libvmaf/test/test_propagate_metadata.c +++ b/libvmaf/test/test_propagate_metadata.c @@ -16,14 +16,14 @@ * */ -#include "propagate_metadata.h" +#include "metadata_handler.h" #include "test.h" void set_meta() {} static char *test_propagate_metadata_init() { - VmafMetadata *propagate_metadata; + VmafCallbackList *propagate_metadata; int err = vmaf_metadata_init(&propagate_metadata); mu_assert("problem during vmaf_propagate_metadata_init", !err); mu_assert("problem during vmaf_propagate_metadata_init, metadata is NULL", @@ -37,7 +37,7 @@ static char *test_propagate_metadata_init() static char *test_propagate_metadata_destroy() { - VmafMetadata *propagate_metadata; + VmafCallbackList *propagate_metadata; int err = vmaf_metadata_init(&propagate_metadata); mu_assert("problem during vmaf_propagate_metadata_init", !err); mu_assert("problem during vmaf_propagate_metadata_init, metadata is NULL", @@ -51,7 +51,7 @@ static char *test_propagate_metadata_destroy() static char *test_propagate_metadata_append() { - VmafMetadata *propagate_metadata; + VmafCallbackList *propagate_metadata; int err = vmaf_metadata_init(&propagate_metadata); mu_assert("problem during vmaf_propagate_metadata_init", !err);