Skip to content

Commit

Permalink
Renaming old structures/files for better naming and new struct for me…
Browse files Browse the repository at this point in the history
…tadata instead of passing as paramaters
  • Loading branch information
yigithanyigit committed Jul 19, 2024
1 parent 249a0e2 commit ade5e71
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 42 deletions.
7 changes: 6 additions & 1 deletion libvmaf/include/libvmaf/libvmaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 8 additions & 5 deletions libvmaf/src/feature/feature_collector.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <string.h>

#include "dict.h"
#include "propagate_metadata.h"
#include "metadata_handler.h"
#include "feature_collector.h"
#include "feature_name.h"
#include "libvmaf/libvmaf.h"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -346,15 +346,14 @@ 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)
{
VmafPredictModel *model_iter = feature_collector->models;
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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions libvmaf/src/feature/feature_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "dict.h"
#include "model.h"
#include "propagate_metadata.h"
#include "metadata_handler.h"

typedef struct {
char *name;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libvmaf/src/libvmaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion libvmaf/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#include <stdlib.h>
#include <string.h>

#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;

Expand All @@ -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));

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
22 changes: 11 additions & 11 deletions libvmaf/src/propagate_metadata.h → libvmaf/src/metadata_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
8 changes: 4 additions & 4 deletions libvmaf/test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/')],
Expand All @@ -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 : [
Expand Down
8 changes: 4 additions & 4 deletions libvmaf/test/test_predict.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdint.h>

#include "feature/feature_collector.h"
#include "propagate_metadata.h"
#include "metadata_handler.h"
#include "test.h"
#include "predict.h"
#include "predict.c"
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions libvmaf/test/test_propagate_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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);

Expand Down

0 comments on commit ade5e71

Please sign in to comment.